Slide 1

Slide 1 text

Kishikawa Katsumi SourceKit-LSPΛϒϥ΢βͰ ίʔυΛಡΉͨΊʹ׆༻͢Δ

Slide 2

Slide 2 text

໨࣍ 1. SourceKit for Safari Demo 2. SourceKit-LSPͱ͸ 3. LSPʢLanguage Server Protocolʣͱ͸ 4. SourceKit-LSPΛ࢖ͬͯΈΔ 5. SourceKit-LSPͱ௨৴͢Δ 6. Safari ExtensionͱSourceKit-LSPΛ࿈ܞ͢Δ 7. iPadͰSourceKit-LSPΛ࢖͏ʂʁ

Slide 3

Slide 3 text

SourceKit for Safari Demo

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

SourceKit for Safari Demo Quick Help popup

Slide 6

Slide 6 text

SourceKit for Safari Demo Quick Help popup

Slide 7

Slide 7 text

SourceKit for Safari Demo Jumps to Definition

Slide 8

Slide 8 text

SourceKit for Safari Demo Find References

Slide 9

Slide 9 text

SourceKit for Safari Demo Highlights References

Slide 10

Slide 10 text

GitHub Code Navigation https://docs.github.com/en/github/managing-files-in-a-repository/navigating-code-on-github

Slide 11

Slide 11 text

SourceKit-LSPͱ͸

Slide 12

Slide 12 text

SourceKit-LSPͱ͸ SourceKit-LSP is an implementation of the Language Server Protocol (LSP) for Swift and C-based languages. It provides features like code-completion and jump-to-definition to editors that support LSP. SourceKit-LSP is built on top of sourcekitd and clangd for high-fidelity language support, and provides a powerful source code index as well as cross-language support. https://github.com/apple/sourcekit-lsp

Slide 13

Slide 13 text

SourceKit-LSPͱ͸ • SwiftɺCɺC++ɺObjective-C༻ͷLanguage Server Protocolͷ࣮૷ • LSPʢLanguage Server ProtocolʣΛαϙʔτ͢ΔςΩετΤσΟλͰ
 ίʔυิ׬΍ఆٛݩʹδϟϯϓͳͲͷػೳ͕࢖͑ΔΑ͏ʹͳΔ • SourceKit-LSP͸sourcekitdͱclangdͱ࿈ܞͯͦ͠ΕΒͷػೳΛఏڙ͍ͯ͠Δ

Slide 14

Slide 14 text

LSPʢLanguage Server Protocolʣͱ͸ Adding features like auto complete, go to definition, or documentation on hover for a programming language takes significant effort. Traditionally this work had to be repeated for each development tool, as each tool provides different APIs for implementing the same feature. A Language Server is meant to provide the language-specific smarts and communicate with development tools over a protocol that enables inter-process communication. The idea behind the Language Server Protocol (LSP) is to standardize the protocol for how such servers and development tools communicate. This way, a single Language Server can be re-used in multiple development tools, which in turn can support multiple languages with minimal effort. https://microsoft.github.io/language-server-protocol/

Slide 15

Slide 15 text

LSPʢLanguage Server Protocolʣͱ͸ LSPʢLanguage Server Protocolʣ͸IDEͰඞཁͱ͞ΕΔιʔείʔυͷΦʔτ ίϯϓϦʔτ΍γϯϘϧͷఆٛݩʹδϟϯϓ͢ΔͳͲͷϓϩάϥϜΛղੳͯ͠ ৘ใΛఏڙ͢ΔػೳΛαʔϏεͱ࣮ͯ͠ݱ͢Δ΋ͷͰ͢ɻ IDEͰඞཁͱ͞ΕΔػೳͱ͍͏΋ͷ͸ɺϓϩάϥϛϯάݴޠ͕มΘͬͯ΋΍Γͨ ͍͜ͱ͸΄΅ಉ͡Ͱ͢ɻLSP͕ొ৔͢ΔҎલ͸ݴޠ͝ͱͷIDE͕ͦΕͧΕ࣮૷͠ ͯఏڙ͍ͯ͠·ͨ͠ɻ LSP͸ɺ͜ͷΑ͏ͳݴޠ͕มΘͬͯ΋ڞ௨ͯ͠ٻΊΒΕΔIDEͷػೳΛந৅Խ͠ ͯ։ൃπʔϧ͔Β࢖͑ΔΑ͏ʹ͢Δ࢓༷Ͱ͢ɻ

Slide 16

Slide 16 text

LSPʢLanguage Server Protocolʣͱ͸ https://nshipster.com/language-server-protocol/

Slide 17

Slide 17 text

SourceKit-LSPΛ࢖ͬͯΈΔ

Slide 18

Slide 18 text

SourceKit-LSPΛ࢖ͬͯΈΔ 1. SourceKit-LSPΛೖख͢Δ 2. ςΩετΤσΟλͰSourceKit-LSPΛར༻͢ΔઃఆΛ͢Δ 3. swift buildίϚϯυͰϓϩδΣΫτΛϏϧυ͢Δ 4. ςΩετΤσΟλͰϓϩδΣΫτΛ։͘ https://github.com/apple/sourcekit-lsp#getting-started

Slide 19

Slide 19 text

SourceKit-LSPΛ࢖ͬͯΈΔ with VS Code 1. SourceKit-LSP Visual Studio Code extensionΛϏϧυɾΠϯετʔϧ 2. VS CodeʹSourceKit-LSPͷઃఆΛ͢Δ https://github.com/apple/sourcekit-lsp/tree/master/Editors#visual-studio-code

Slide 20

Slide 20 text

SourceKit-LSPΛ࢖ͬͯΈΔ Visual Studio Code extensionΛϏϧυɾΠϯετʔϧ

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

xcrun --find sourcekit-lsp

Slide 23

Slide 23 text

SourceKit-LSPΛ࢖ͬͯΈΔ

Slide 24

Slide 24 text

SourceKit-LSPΛ࢖ͬͯΈΔ

Slide 25

Slide 25 text

SourceKit-LSPΛ࢖ͬͯΈΔ iOS SDKΛར༻͢ΔઃఆΛ௥Ճ

Slide 26

Slide 26 text

SourceKit-LSPΛ࢖ͬͯΈΔ

Slide 27

Slide 27 text

SourceKit-LSPͱ௨৴͢Δ

Slide 28

Slide 28 text

SourceKit-LSPͱ௨৴͢Δ https://microsoft.github.io/language-server-protocol/overviews/lsp/overview/ A language server runs as a separate process and development tools communicate with the server using the language protocol over JSON-RPC.

Slide 29

Slide 29 text

SourceKit-LSPͱ௨৴͢Δ https://microsoft.github.io/language-server-protocol/overviews/lsp/overview/ Request Response

Slide 30

Slide 30 text

SourceKit-LSPͱ௨৴͢Δ https://microsoft.github.io/language-server-protocol/specifications/specification-current/ Request Response Content-Length: ...\r\n \r\n { "jsonrpc": "2.0", "id": 1, "method": "textDocument/didOpen", "params": { ... } } Header Content

Slide 31

Slide 31 text

㽟 㽠 㽡

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

SourceKit-LSPͱ௨৴͢Δ VS Code LSP initialize initialized didOpen hover hover didOpen hover

Slide 34

Slide 34 text

SourceKit-LSPͱ௨৴͢Δ The protocol does not make any provisions about how requests, responses and notifications are transferred between client and server. https://en.wikipedia.org/wiki/Language_Server_Protocol#Transport_layer

Slide 35

Slide 35 text

SourceKit-LSPͱ௨৴͢Δ The protocol does not make any provisions about how requests, responses and notifications are transferred between client and server. In this implementation, an editor communicates through stdin/stdout with the TypeScript server process and uses a JSON payload https://en.wikipedia.org/wiki/Language_Server_Protocol#Transport_layer https://docs.microsoft.com/en-us/visualstudio/extensibility/language-server-protocol?view=vs-2019#how-work-on-the-lsp-started

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

SourceKit-LSPͱ௨৴͢Δ

Slide 38

Slide 38 text

SourceKit-LSPͱ௨৴͢Δ

Slide 39

Slide 39 text

SourceKit-LSPͱ௨৴͢Δ

Slide 40

Slide 40 text

SourceKit-LSPͱ௨৴͢Δ

Slide 41

Slide 41 text

SourceKit-LSPͱ௨৴͢Δ

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

Symbols Hover

Slide 44

Slide 44 text

https://github.com/kishikawakatsumi/SourceKitForSafari SourceKit-LSPͱ௨৴͢Δ

Slide 45

Slide 45 text

https://github.com/kishikawakatsumi/SourceKitForSafari

Slide 46

Slide 46 text

https://github.com/kishikawakatsumi/SourceKitForSafari SourceKit-LSPͱ௨৴͢Δ

Slide 47

Slide 47 text

Safari Extensionͱ SourceKit-LSPΛ࿈ܞ͢Δ

Slide 48

Slide 48 text

Safari ExtensionͱSourceKit-LSPΛ࿈ܞ͢Δ Safari Extension https://developer.apple.com/documentation/safariservices/safari_app_extensions

Slide 49

Slide 49 text

Safari ExtensionͱSourceKit-LSPΛ࿈ܞ͢Δ Safari Extension

Slide 50

Slide 50 text

Safari ExtensionͱSourceKit-LSPΛ࿈ܞ͢Δ Safari Extension SourceKit-LSP

Slide 51

Slide 51 text

Chrome ExtensionͱSourceKit-LSPΛ࿈ܞ͢Δ Chrome Extension SourceKit-LSP Native Messaging

Slide 52

Slide 52 text

Safari ExtensionͱSourceKit-LSPΛ࿈ܞ͢Δ App Side

Slide 53

Slide 53 text

Safari ExtensionͱSourceKit-LSPΛ࿈ܞ͢Δ JS Side

Slide 54

Slide 54 text

iPadͰSourceKit-LSPΛ࢖͏ʂʁ

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

·ͱΊ • SourceKit-LSPΛ࢖͏ͱXcode͕ఏڙ͍ͯ͠Δίʔυิ׬΍ϦϑΝΫλϦϯά ͷ৘ใΛऔಘͰ͖Δ • SourceKit-LSP͸ΫϥΠΞϯτϥΠϒϥϦ΋͋ΔͷͰ࿈ܞ͢Δ͜ͱ͸೉͘͠ͳ ͍ • HTTPӽ͠ʹSourceKit-LSPΛૢ࡞͢ΔͱXcode for iOS͕࡞ΕΔ͔΋ʁ • SourceKit for SafariʢChrome֦ு΋͋Γ·͢ʣࢀߟʹ͍ͯͩ͘͠͞
 https://github.com/kishikawakatsumi/SourceKitForSafari