GithubHelp home page GithubHelp logo

emacs-lsp / lsp-sourcekit Goto Github PK

View Code? Open in Web Editor NEW
102.0 8.0 12.0 2.06 MB

lsp-mode :heart: Apple's sourcekit

Home Page: https://emacs-lsp.github.io/lsp-sourcekit

License: GNU General Public License v3.0

Emacs Lisp 90.70% Makefile 9.30%
swift sourcekit emacs language-server-protocol emacs-lsp apple lsp-sourcekit sourcekit-lsp swift-toolchain

lsp-sourcekit's Introduction

title description root_file
LSP Mode - Language Server Protocol support for Emacs
Language Server Protocol support with multiples languages support for Emacs
README.md

CI

Language Server Protocol Support for Emacs

LSP mode


homepageinstallationlanguagessettingstutorialstroubleshootingscreenshotsFAQ


Why?

  • ❤️ Community Driven
  • 💎 Fully featured - supports all features in Language Server Protocol v3.14.
  • 🚀 Fast - see performance section.
  • 🌟 Flexible - choose between full-blown IDE with flashy UI or minimal distraction free.
  • ⚙️ Easy to configure - works out of the box and automatically upgrades if additional packages are present.

Overview

Client for Language Server Protocol (v3.14). lsp-mode aims to provide IDE-like experience by providing optional integration with the most popular Emacs packages like company, flycheck and projectile.

  • Non-blocking asynchronous calls
  • Real-time Diagnostics/linting via flycheck (recommended) or flymake when Emacs > 26 (requires flymake>=1.0.5)
  • Code completion - company-capf / completion-at-point (note that company-lsp is no longer supported).
  • Hovers - using lsp-ui
  • Code actions - via lsp-execute-code-action, modeline (recommended) or lsp-ui sideline.
  • Code outline - using builtin imenu or helm-imenu
  • Code navigation - using builtin xref, lsp-treemacs tree views or lsp-ui peek functions.
  • Code lens
  • Symbol highlights
  • Formatting
  • Project errors on modeline
  • Debugger - dap-mode
  • Breadcrumb on headerline
  • Helm integration - helm-lsp
  • Ivy integration - lsp-ivy
  • Consult integration - consult-lsp
  • Treemacs integration - lsp-treemacs
  • Semantic tokens as defined by LSP 3.16 (compatible language servers include recent development builds of clangd and rust-analyzer)
  • which-key integration for better discovery
  • iedit
  • dired
  • ido

Presentations/demos

See also

  • lsp-docker - provide docker image with preconfigured language servers with corresponding emacs configuration.
  • company-box - company frontend with icons.
  • dap-mode - Debugger integration for lsp-mode.
  • eglot - An alternative minimal LSP implementation.
  • which-key - Emacs package that displays available keybindings in popup
  • projectile - Project Interaction Library for Emacs
  • emacs-tree-sitter - Faster, fine-grained code highlighting via tree-sitter.
  • gccemacs - modified Emacs capable of compiling and running Emacs Lisp as native code.

Contributions

Contributions are very much welcome!

NOTE Documentation for clients is generated from doc comments in the clients themselves (see lsp-doc.el) and some metadata (see lsp-clients.json) so please submit corrections accordingly.

Support the project

The emacs-lsp organization has more than 20,000 lines of code, to keep all of this working, we need to implement new features and help the community on a lot of issues.

You can help us keep going and improving it by supporting the project

Members

Here it is a list of the current lsp-mode members and what they are primary working on/responsible for.

kurnevsky
kurnevsky

Scala | Rust
seagle0128
seagle0128

Go | Python MS
sebastiansturm
sebastiansturm

lsp-mode core | C++
vibhavp
vibhavp

lsp-mode core
yyoncho
yyoncho

lsp-mode core | Java
ericdallo
ericdallo

Dart/Flutter | Clojure
danielmartin
danielmartin

C++ | Swift
kiennq
kiennq

completions | pwsh
nbfalcon
nbfalcon

lsp-mode core | iedit
psibi
psibi

Terraform | Nix
razzmatazz
razzmatazz

C# | F#
jcs090218
jcs090218

lsp-mode core

lsp-sourcekit's People

Contributors

dani84bs avatar danielmartin avatar divinedominion avatar duianto avatar ericdallo avatar jcs090218 avatar slippycheeze avatar yyoncho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lsp-sourcekit's Issues

completion stops working after error

i have made the experience that after opening a .swift file
and setting the project's root dir i get successful completion

but after one interrupts the completion by keep typing an error occurs,
and no more completion after that.
I suspect it is because sourcekit-lsp crashed

swift version: 5.4.2

lsp error message:

# Table of Contents
2021-07-19 08:11:59.454 sourcekit-lsp[62:ef66e700] triggerFromIncompleteCompletions with incompatible completion session; expected DocumentURI(storage: <file:///work/cards/service/api/Sources/api/User/ControllerUser.swift>)@1215, but got DocumentURI(storage: <file:///work/cards/service/api/Sources/api/User/ControllerUser.swift>)@1224

company error message:

Company: An error occurred in auto-begin
Company: backend (company-capf :with company-yasnippet) error &ldquo;request cancelled&rdquo; with args (candidates fun)

second lsp error message:

2021-07-19 11:00:04.025 sourcekit-lsp[82:8ffff700] error response (Request Failed): codecomplete.open: code completion session for &rsquo;/work/cards/service/api/Sources/api/User/Controller+User.swift&rsquo;, 1166 already exists

backtrace:

stacktrace:

  • 1
  • the second got too long to post

after installing a missing dependency libpython2.7 the error still persists.
namely that the lsp server becomes unresponsive.and completion stops working

additionally i tried:

  • successfully build the project before provoking the error
  • built sourcekit-lsp from source
  • downgraded swift to 5.4
  • used no included framework vanilla swift from swift package init

it seems the trace shows nothing but the empty response from the sourcekit-lsp server.
the error messages differ only from the DocumentURI (which is the same for
expected and for received) and the char number @1151 (which differs between expected and received).

no such module 'UIKit'

this is my configuration:

(use-package lsp-sourcekit
  :ensure t
  :after lsp-mode
  :config
  (setq lsp-sourcekit-executable "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/sourcekit-lsp")
  (setq lsp-sourcekit-extra-args (quote
				  ("-Xswiftc" "-sdk" "-Xswiftc" "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk" "-Xswiftc" "-target" "-Xswiftc" "x86_64-apple-ios13.6-simulator")
				  )
	)
  )

"could not open compilation database for /path/to/Foo.swift"

I can only get lsp-sourcekit to give me the following in *Messages* buffer:

could not find manifest, or not a SwiftPM package: /path/to/current/directory
could not open compilation database for /path/to/current/directory/Foo.swift [3 times]

Do I need to have a SwiftPM package for my project in order to do anything?

Emacs 25 incompatibility

Hi,
I'm using Ubuntu 18.04 LTS, which comes with emacs 25.2.2
Installing lsp-sourcekit fails with Package 'emacs-26.1' is unavailable.

After some investigation, it looks like emacs 25 support was removed from lsp-mode:
emacs-lsp/lsp-mode#1668

Could we pin this package to an older version of lsp-mode?

lsp-sourcekit can't get complete candidates

company-mode displays error in minibuffer:

Company: An error occurred in auto-begin
Company: backend company-capf error "request cancelled" with args (candidates let)

Then I enabled lsp-mode debug with:

(setq lsp-log-io t
      lsp-print-io t)

In buffer *lsp-log: sourcekit-ls:55049*:

[Trace - 05:53:52 PM] Received response 'textDocument/codeAction - (53)' in 28ms.
Result: []


[Trace - 05:53:58 PM] Sending request 'textDocument/codeAction - (54)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
  },
  "range": {
    "start": {
      "line": 8,
      "character": 0
    },
    "end": {
      "line": 8,
      "character": 0
    }
  },
  "context": {
    "diagnostics": []
  }
}


[Trace - 05:53:58 PM] Received response 'textDocument/codeAction - (54)' in 22ms.
Result: []


[Trace - 05:53:58 PM] Sending notification 'textDocument/didChange'.
Params: {
  "textDocument": {
    "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift",
    "version": 54
  },
  "contentChanges": [
    {
      "range": {
        "start": {
          "line": 8,
          "character": 0
        },
        "end": {
          "line": 8,
          "character": 0
        }
      },
      "rangeLength": 0,
      "text": "l"
    }
  ]
}


[Trace - 05:53:58 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "diagnostics": [],
  "version": 54,
  "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
}


[Trace - 05:53:58 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "diagnostics": [
    {
      "relatedInformation": [],
      "severity": 1,
      "source": "sourcekitd",
      "message": "cannot find 'l' in scope",
      "range": {
        "end": {
          "character": 0,
          "line": 8
        },
        "start": {
          "character": 0,
          "line": 8
        }
      }
    },
    {
      "relatedInformation": [],
      "severity": 1,
      "source": "sourcekitd",
      "message": "expressions are not allowed at the top level",
      "range": {
        "end": {
          "character": 0,
          "line": 8
        },
        "start": {
          "character": 0,
          "line": 8
        }
      }
    }
  ],
  "version": 54,
  "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
}


[Trace - 05:53:58 PM] Sending notification 'textDocument/didChange'.
Params: {
  "textDocument": {
    "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift",
    "version": 55
  },
  "contentChanges": [
    {
      "range": {
        "start": {
          "line": 8,
          "character": 1
        },
        "end": {
          "line": 8,
          "character": 1
        }
      },
      "rangeLength": 0,
      "text": "e"
    }
  ]
}


[Trace - 05:53:58 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "diagnostics": [
    {
      "relatedInformation": [],
      "severity": 1,
      "source": "sourcekitd",
      "message": "cannot find 'l' in scope",
      "range": {
        "end": {
          "character": 0,
          "line": 8
        },
        "start": {
          "character": 0,
          "line": 8
        }
      }
    },
    {
      "relatedInformation": [],
      "severity": 1,
      "source": "sourcekitd",
      "message": "expressions are not allowed at the top level",
      "range": {
        "end": {
          "character": 0,
          "line": 8
        },
        "start": {
          "character": 0,
          "line": 8
        }
      }
    }
  ],
  "version": 55,
  "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
}


[Trace - 05:53:58 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "diagnostics": [
    {
      "relatedInformation": [],
      "severity": 1,
      "source": "sourcekitd",
      "message": "cannot find 'le' in scope",
      "range": {
        "end": {
          "character": 0,
          "line": 8
        },
        "start": {
          "character": 0,
          "line": 8
        }
      }
    },
    {
      "relatedInformation": [],
      "severity": 1,
      "source": "sourcekitd",
      "message": "expressions are not allowed at the top level",
      "range": {
        "end": {
          "character": 0,
          "line": 8
        },
        "start": {
          "character": 0,
          "line": 8
        }
      }
    }
  ],
  "version": 55,
  "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
}


[Trace - 05:53:58 PM] Sending notification 'textDocument/didChange'.
Params: {
  "textDocument": {
    "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift",
    "version": 56
  },
  "contentChanges": [
    {
      "range": {
        "start": {
          "line": 8,
          "character": 2
        },
        "end": {
          "line": 8,
          "character": 2
        }
      },
      "rangeLength": 0,
      "text": "t"
    }
  ]
}


[Trace - 05:53:58 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "diagnostics": [
    {
      "relatedInformation": [],
      "severity": 1,
      "source": "sourcekitd",
      "message": "expected pattern",
      "range": {
        "end": {
          "character": 3,
          "line": 8
        },
        "start": {
          "character": 3,
          "line": 8
        }
      }
    },
    {
      "relatedInformation": [],
      "severity": 1,
      "source": "sourcekitd",
      "message": "cannot find 'le' in scope",
      "range": {
        "end": {
          "character": 0,
          "line": 8
        },
        "start": {
          "character": 0,
          "line": 8
        }
      }
    },
    {
      "relatedInformation": [],
      "severity": 1,
      "source": "sourcekitd",
      "message": "expressions are not allowed at the top level",
      "range": {
        "end": {
          "character": 0,
          "line": 8
        },
        "start": {
          "character": 0,
          "line": 8
        }
      }
    }
  ],
  "version": 56,
  "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
}


[Trace - 05:53:58 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "diagnostics": [
    {
      "relatedInformation": [],
      "severity": 1,
      "source": "sourcekitd",
      "message": "expected pattern",
      "range": {
        "end": {
          "character": 3,
          "line": 8
        },
        "start": {
          "character": 3,
          "line": 8
        }
      }
    }
  ],
  "version": 56,
  "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
}


[Trace - 05:53:58 PM] Sending request 'textDocument/completion - (55)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
  },
  "position": {
    "line": 8,
    "character": 3
  },
  "context": {
    "triggerKind": 3
  }
}


[Trace - 05:53:58 PM] Received response 'textDocument/completion - (55)' in 2ms.
Result: {
  "code": -32800,
  "message": "request cancelled"
}


[Trace - 05:53:58 PM] Sending request 'textDocument/completion - (56)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
  },
  "position": {
    "line": 8,
    "character": 3
  },
  "context": {
    "triggerKind": 3
  }
}


[Trace - 05:53:58 PM] Received response 'textDocument/completion - (56)' in 42ms.
Result: {
  "code": -32800,
  "message": "request cancelled"
}


[Trace - 05:54:00 PM] Sending notification 'textDocument/didChange'.
Params: {
  "textDocument": {
    "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift",
    "version": 57
  },
  "contentChanges": [
    {
      "range": {
        "start": {
          "line": 8,
          "character": 0
        },
        "end": {
          "line": 8,
          "character": 3
        }
      },
      "rangeLength": 3,
      "text": ""
    }
  ]
}


[Trace - 05:54:00 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "diagnostics": [
    {
      "relatedInformation": [],
      "severity": 1,
      "source": "sourcekitd",
      "message": "expected pattern",
      "range": {
        "end": {
          "character": 3,
          "line": 8
        },
        "start": {
          "character": 3,
          "line": 8
        }
      }
    }
  ],
  "version": 57,
  "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
}


[Trace - 05:54:00 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "diagnostics": [],
  "version": 57,
  "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
}


[Trace - 05:54:00 PM] Sending notification 'textDocument/willSave'.
Params: {
  "textDocument": {
    "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift"
  },
  "reason": 1
}


[Trace - 05:54:00 PM] Sending notification 'textDocument/didSave'.
Params: {
  "textDocument": {
    "uri": "file:///Users/stardiviner/Documents/Programming/Swift/SwiftDemo/Sources/SwiftDemo/SwiftDemo.swift",
    "version": 57
  }
}

No completion on basic SPM project (Xcode 12 beta)

Completion of Apple frameworks work really well. Thank you! Completion of my own types within a basic SPM project don't seem to be working:

Screenshot 2020-07-06 at 19 05 27

Also no completion in FooBar.swift:

struct FooBar {
  static func main() {
    let foo = Foo()
    foo.sing()
    foo. // <- No completion here
  }
}

Am I misconfiguring things?

(use-package lsp-sourcekit
    :config
    (setq lsp-sourcekit-extra-args (list "--log-level" "debug"))
    (setq lsp-sourcekit-executable "/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/sourcekit-lsp"))

Project builds otherwise:

$ swift build
[1/2] Compiling FooBar Foo.swift
[2/2] Compiling FooBar FooBar.swift
[3/3] Merging module FooBar

My Package.swift

// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
  name: "FooBar",
  products: [
    .library(
      name: "FooBar",
      targets: ["FooBar"])
  ],
  targets: [
    .target(
      name: "FooBar",
      dependencies: []),
    .testTarget(
      name: "FooBarTests",
      dependencies: ["FooBar"]),
  ]
)

Project structure

$ find FooBar
FooBar
FooBar/Tests
FooBar/Tests/LinuxMain.swift
FooBar/Tests/FooBarTests
FooBar/Tests/FooBarTests/XCTestManifests.swift
FooBar/Tests/FooBarTests/FooBarTests.swift
FooBar/README.md
FooBar/.gitignore
FooBar/Package.swift
FooBar/Sources
FooBar/Sources/FooBar
FooBar/Sources/FooBar/FooBar.swift
FooBar/Sources/FooBar/Foo.swift

Foo.swift content

public struct Foo {
  public func sing() {
    print("singing")
  }
}

Configuration Help

I'm trying to configure doom-emacs (develop branch of https://github.com/hlissner/doom-emacs) and lsp-sourcekit, but can't seem to get it working. Here's what I have in my config.el:

(after! lsp-sourcekit
  :config
  (setenv "SOURCEKIT_TOOLCHAIN_PATH" "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain")
  (setq lsp-sourcekit-executable "/Users/rudedogg/Desktop/Contrib/sourcekit-lsp/.build/debug/sourcekit-lsp"))

But when I try to enable lsp, I get LSP :: No LSP server for swift-mode.. I think the toolchain/sourcekit-lsp is working with Sublime Text 3 and VS Code, but can't seem to get it going with emacs.

I know this is probably a config issue on my end, and understand if it's out of scope. If so feel free to close.

Lagging interface with company-mode

I'm using lsp-sourcekit with company-mode as part of an Doom Emacs configuration.

When I start typing and company wants to present auto completion, the interface freezes for about a second. Then I'm presented with an extremely long list of auto completion possibilities:

Screen Shot 2019-11-10 at 21 52 48

This only happens when I start typing. There is no issue, when I've got the type written out and just look for members of the type.
Abc. is working fine and presents the init, Type and self.

Example of working config?

I managed to get some autocomplete working but not for properties of a class/struct. It also stops working very often.

Does anyone have any pointers how to get it to work? Any other better options?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.