Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SourceKit-LSPを使ってWebブラウザでSwiftの入力補完を実現する

 SourceKit-LSPを使ってWebブラウザでSwiftの入力補完を実現する

- SwiftFiddle (Online Playground) Demo
- 標準ライブラリの関数などをコード補完する
- SourceKit-LSPと通信する
- Text Document Synchronization
- システム構成と実装

Kishikawa Katsumi

September 29, 2020
Tweet

More Decks by Kishikawa Katsumi

Other Decks in Programming

Transcript

  1. SourceKit-LSPͱ௨৴͢Δ Client SourceKit-LSP initialize didOpen hover { workspace: ~/projects/MySwiftApp }

    { documentURI: src/main.swift, text: "import Foundation ..." } { documentURI: src/main.swift, position: { row: 32, col: 7} }
  2. SourceKit-LSPͱ௨৴͢Δ Client SourceKit-LSP initialize didOpen hover { workspace: ~/projects/MySwiftApp }

    { documentURI: src/main.swift, text: "import Foundation ..." } { documentURI: src/main.swift, position: { row: 32, col: 7} }
  3. SourceKit-LSPͱ௨৴͢Δ Client SourceKit-LSP didOpen didChange { documentURI: src/main.swift, version: 2,

    contentChanges: ... } didChange { ..., version: 3, contentChanges: ... } completion
  4. Text Document Synchronization Client support for textDocument/didOpen, textDocument/ didChange and

    textDocument/didClose notifications is mandatory in the protocol and clients can not opt out supporting them. This includes both full and incremental syncronization in the textDocument/didChange notification. In addition a server must either implement all three of them or none. Their capabilities are therefore controlled via a combined client and server capability. https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_synchronization
  5. Text Document Synchronization The actual content changes. The content changes

    describe single state changes to the document. So if there are two content changes c1 (at array index 0) and c2 (at array index 1) for a document in state S then c1 moves the document from S to S' and c2 from S' to S''. So c1 is computed on the state S and c2 is computed on the state S'. To mirror the content of a document using change events use the following approach: - start with the same initial content - apply the 'textDocument/didChange' notifications in the order you recevie them. - apply the `TextDocumentContentChangeEvent`s in a single notification in the order you receive them. https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_synchronization
  6. Text Document Synchronization /// A change to a text document.

    /// /// If `range` and `rangeLength` are unspecified, /// the whole document content is replaced. /// public struct TextDocumentContentChangeEvent: Codable, Hashable { https://github.com/apple/sourcekit-lsp
  7. LSP