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



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を使う!?

w/ Presenter Note


Kishikawa Katsumi

September 19, 2020

More Decks by Kishikawa Katsumi

Other Decks in Programming


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

  2. ໨࣍ 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Λ࢖͏ʂʁ
  3. SourceKit for Safari Demo

  4. None
  5. SourceKit for Safari Demo Quick Help popup

  6. SourceKit for Safari Demo Quick Help popup

  7. SourceKit for Safari Demo Jumps to Definition

  8. SourceKit for Safari Demo Find References

  9. SourceKit for Safari Demo Highlights References

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

  11. SourceKit-LSPͱ͸

  12. 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
  13. SourceKit-LSPͱ͸ • SwiftɺCɺC++ɺObjective-C༻ͷLanguage Server Protocolͷ࣮૷ • LSPʢLanguage Server ProtocolʣΛαϙʔτ͢ΔςΩετΤσΟλͰ

    • SourceKit-LSP͸sourcekitdͱclangdͱ࿈ܞͯͦ͠ΕΒͷػೳΛఏڙ͍ͯ͠Δ
  14. 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/
  15. LSPʢLanguage Server Protocolʣͱ͸ LSPʢLanguage Server Protocolʣ͸IDEͰඞཁͱ͞ΕΔιʔείʔυͷΦʔτ ίϯϓϦʔτ΍γϯϘϧͷఆٛݩʹδϟϯϓ͢ΔͳͲͷϓϩάϥϜΛղੳͯ͠ ৘ใΛఏڙ͢ΔػೳΛαʔϏεͱ࣮ͯ͠ݱ͢Δ΋ͷͰ͢ɻ IDEͰඞཁͱ͞ΕΔػೳͱ͍͏΋ͷ͸ɺϓϩάϥϛϯάݴޠ͕มΘͬͯ΋΍Γͨ ͍͜ͱ͸΄΅ಉ͡Ͱ͢ɻLSP͕ొ৔͢ΔҎલ͸ݴޠ͝ͱͷIDE͕ͦΕͧΕ࣮૷͠

    ͯఏڙ͍ͯ͠·ͨ͠ɻ LSP͸ɺ͜ͷΑ͏ͳݴޠ͕มΘͬͯ΋ڞ௨ͯ͠ٻΊΒΕΔIDEͷػೳΛந৅Խ͠ ͯ։ൃπʔϧ͔Β࢖͑ΔΑ͏ʹ͢Δ࢓༷Ͱ͢ɻ
  16. LSPʢLanguage Server Protocolʣͱ͸ https://nshipster.com/language-server-protocol/

  17. SourceKit-LSPΛ࢖ͬͯΈΔ

  18. SourceKit-LSPΛ࢖ͬͯΈΔ 1. SourceKit-LSPΛೖख͢Δ 2. ςΩετΤσΟλͰSourceKit-LSPΛར༻͢ΔઃఆΛ͢Δ 3. swift buildίϚϯυͰϓϩδΣΫτΛϏϧυ͢Δ 4. ςΩετΤσΟλͰϓϩδΣΫτΛ։͘

  19. 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
  20. SourceKit-LSPΛ࢖ͬͯΈΔ Visual Studio Code extensionΛϏϧυɾΠϯετʔϧ

  21. None
  22. xcrun --find sourcekit-lsp

  23. SourceKit-LSPΛ࢖ͬͯΈΔ

  24. SourceKit-LSPΛ࢖ͬͯΈΔ

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

  26. SourceKit-LSPΛ࢖ͬͯΈΔ

  27. SourceKit-LSPͱ௨৴͢Δ

  28. 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.
  29. SourceKit-LSPͱ௨৴͢Δ https://microsoft.github.io/language-server-protocol/overviews/lsp/overview/ Request Response

  30. 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
  31. 㽟 㽠 㽡

  32. None
  33. SourceKit-LSPͱ௨৴͢Δ VS Code LSP initialize initialized didOpen hover hover didOpen

  34. 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
  35. 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
  36. None
  37. SourceKit-LSPͱ௨৴͢Δ

  38. SourceKit-LSPͱ௨৴͢Δ

  39. SourceKit-LSPͱ௨৴͢Δ

  40. SourceKit-LSPͱ௨৴͢Δ

  41. SourceKit-LSPͱ௨৴͢Δ

  42. None
  43. Symbols Hover

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

  45. https://github.com/kishikawakatsumi/SourceKitForSafari

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

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

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

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

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

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

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

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

  54. iPadͰSourceKit-LSPΛ࢖͏ʂʁ

  55. None
  56. ·ͱΊ • SourceKit-LSPΛ࢖͏ͱXcode͕ఏڙ͍ͯ͠Δίʔυิ׬΍ϦϑΝΫλϦϯά ͷ৘ใΛऔಘͰ͖Δ • SourceKit-LSP͸ΫϥΠΞϯτϥΠϒϥϦ΋͋ΔͷͰ࿈ܞ͢Δ͜ͱ͸೉͘͠ͳ ͍ • HTTPӽ͠ʹSourceKit-LSPΛૢ࡞͢ΔͱXcode for

    iOS͕࡞ΕΔ͔΋ʁ • SourceKit for SafariʢChrome֦ு΋͋Γ·͢ʣࢀߟʹ͍ͯͩ͘͠͞