Slide 1

Slide 1 text

Kishikawa Katsumi SourceKit-LSPΛ࢖ͬͯWeb ϒϥ΢βͰSwiftͷೖྗิ׬Λ࣮ݱ͢Δ

Slide 2

Slide 2 text

໨࣍ 1. SwiftFiddle (Online Playground) Demo 2. ඪ४ϥΠϒϥϦͷؔ਺ͳͲΛίʔυิ׬͢Δ 1. SourceKit-LSPͱ௨৴͢Δ 2. Text Document Synchronization 3. γεςϜߏ੒ͱ࣮૷

Slide 3

Slide 3 text

SwiftFiddle Demo https://www.swiftfiddle.com/

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

ඪ४ϥΠϒϥϦͷؔ਺ͳͲΛ ίʔυิ׬͢Δ

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

SourceKit-LSPͱ௨৴͢Δ Client SourceKit-LSP initialize initialized didOpen hover hover definitions hover references

Slide 10

Slide 10 text

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} }

Slide 11

Slide 11 text

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} }

Slide 12

Slide 12 text

SourceKit-LSPͱ௨৴͢Δ Client SourceKit-LSP didOpen didChange { documentURI: src/main.swift, version: 2, contentChanges: ... } didChange { ..., version: 3, contentChanges: ... } completion

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_synchronization

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Text Document Synchronization S contentChange contentChange contentChange didChange

Slide 17

Slide 17 text

Text Document Synchronization S contentChange contentChange contentChange didChange S′

Slide 18

Slide 18 text

Text Document Synchronization S′ contentChange contentChange didChange S′′

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

Text Document Synchronization https://github.com/kishikawakatsumi/swift-playground

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

LSP

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

GitHub Codespaces

Slide 32

Slide 32 text

GitHub Codespaces

Slide 33

Slide 33 text

References • https://swiftfiddle.com • https://github.com/kishikawakatsumi/swift-playground • https://github.com/kishikawakatsumi/SwiftFiddleEditor • https://github.com/kishikawakatsumi/SourceKitForSafari • https://github.com/apple/sourcekit-lsp • https://microsoft.github.io/language-server-protocol/ • https://ace.c9.io/