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

Emacs で LSP を使ってみたよ

Taiju Aoki
January 23, 2019

Emacs で LSP を使ってみたよ

Slide for M3 TechTalk

Taiju Aoki

January 23, 2019
Tweet

More Decks by Taiju Aoki

Other Decks in Programming

Transcript

  1. Who Am I ‣ VTuber ͱ Emacs ޷͖ͷ׽ ‣ ࣾձਓ

    10ϲ݄໨ ͷεʔύʔΤϯδχΞ blue (@blue_1617) ࠷ۙͷ Emacs ͳ׆ಈ ‣ ౦ژ Emacs ๨೥ձ 2018 ‣ (nth 2 shibuyaku-elisp) ‣ GitHub/flycheck-flash-mode-line ‣ GitHub/electron-desktop-character ࠷ۙͷ OSS ͳ׆ಈ ‣ GitHub/cycle-frame-transparency ࠷ۙͷ Qiita ͳ׆ಈ ‣ Emacs Ͱ LSP Λ׆༻ͯ͠ΈΔ ‣ 2018೥͚ͩͲσεΫτοϓϚείοτΛ ࡞Γ͔ͨͬͨΜͩ ‣ Emacs ΛϫϯίϚϯυͰಁաͤ͞Δ ‣ flycheck Ͱ Emacs ͷ Mode Line ΛޫΒͤΔ ‣ counsel-recentf ͷର৅Λ Project ಺ϑΝΠϧ ʹߜΔ ‣ Emacs Ͱࣗ࡞ؔ਺Λ࢖ͬͯΈΔ ࠷ۙ࡞ͬͨϙʔτϑΥϦΦ (https://blue0513.github.io/show_room/)
  2. LSPͱ͸ʁ Language Server Protocol (JSON-RPC) Development Tool Notification: textDocument/didChange; Params:

    {documentURI, changes} Notification: textDocument/publishDiagnostics; Params: Diagnostic[] Language Server Request: textDocument/definition; Params: {documentURI, position} Notification: textDocument/didOpen; Params: document Open document Edit document Goto definition Publish Publish Response: textDocument/definition; Result: Location https://microsoft.github.io/language-server-protocol/overview
  3. LSPͱ͸ʁ Language Server Protocol (JSON-RPC) Notification: textDocument/didChange; Params: {documentURI, changes}

    Notification: textDocument/publishDiagnostics; Params: Diagnostic[] Language Server Request: textDocument/definition; Params: {documentURI, position} Notification: textDocument/didOpen; Params: document Open document Edit document Goto definition Publish Publish Response: textDocument/definition; Result: Location https://microsoft.github.io/language-server-protocol/overview Development Tool ΤσΟλͱ͔
  4. LSPͱ͸ʁ Language Server Protocol (JSON-RPC) Development Tool Notification: textDocument/didChange; Params:

    {documentURI, changes} Notification: textDocument/publishDiagnostics; Params: Diagnostic[] Request: textDocument/definition; Params: {documentURI, position} Notification: textDocument/didOpen; Params: document Open document Edit document Goto definition Publish Publish Response: textDocument/definition; Result: Location https://microsoft.github.io/language-server-protocol/overview Language Server ιʔείʔυͷղੳΛͯ͘͠ΕΔαʔό ʢϩʔΧϧʹཱͯΒΕΔʣ
  5. LSPͱ͸ʁ Development Tool Notification: textDocument/didChange; Params: {documentURI, changes} Notification: textDocument/publishDiagnostics;

    Params: Diagnostic[] Request: textDocument/definition; Params: {documentURI, position} Notification: textDocument/didOpen; Params: document Open document Edit document Goto definition Publish Publish Response: textDocument/definition; Result: Location https://microsoft.github.io/language-server-protocol/overview Language Server ͜Ε͕ LSP ΤσΟλͱαʔόؒͷ௨৴ϓϩτίϧ Language Server Protocol (JSON-RPC)
  6. LSPͱ͸ʁ Language Server Protocol (JSON-RPC) Development Tool Notification: textDocument/didChange; Params:

    {documentURI, changes} Notification: textDocument/publishDiagnostics; Params: Diagnostic[] Language Server Request: textDocument/definition; Params: {documentURI, position} Notification: textDocument/didOpen; Params: document Open document Edit document Goto definition Publish Publish Response: textDocument/definition; Result: Location https://microsoft.github.io/language-server-protocol/overview
  7. LSPͱ͸ʁ Language Server Protocol (LSP) ͱ͸..... ݴޠͷղੳͳͲΛߦ͏ Language Server ͱ֤πʔϧʢClientʣ͕

    ௨৴ɾ࿈ܞ͢ΔࡍͷϓϩτίϧΛنఆ͢Δ΋ͷ ‣ ֤πʔϧ͸ Language Server ͕ͲͷݴޠΛѻ͍ͬͯΔ͔Λҙࣝ͢ Δ͜ͱͳ͘ɺิ׬΍ఆٛࢀরΛߦ͑Δ ϝϦοτ͸..... https://microsoft.github.io/language-server-protocol/ ‣ Emacs ౳ͷΤσΟλͷ ิ׬ɾఆٛࢀরೳྗ౳͕޲্ ͢Δ
  8. LSPͱ͸ʁ Language Server Protocol (LSP) ͱ͸..... ݴޠͷղੳͳͲΛߦ͏ Language Server ͱ֤πʔϧʢClientʣ͕

    ௨৴ɾ࿈ܞ͢ΔࡍͷϓϩτίϧΛنఆ͢Δ΋ͷ ‣ ֤πʔϧ͸ Language Server ͕ͲͷݴޠΛѻ͍ͬͯΔ͔Λҙࣝ͢ Δ͜ͱͳ͘ɺิ׬΍ఆٛࢀরΛߦ͑Δ ϝϦοτ͸..... https://microsoft.github.io/language-server-protocol/ ‣ Emacs ౳ͷΤσΟλͷ ิ׬ɾఆٛࢀরೳྗ౳͕޲্ ͢Δ LSP Ͱ Emacs ͕ڧ͘ͳΔʂ ΍ͬͨͥ
  9. Emacs Ͱ LSP Λ׆༻ͯ͠ΈΔ Developer Tool Language Server Language Server

    Protocol (JSON-RPC) (Host) Development Tool Ruby JavaScript Java Request: textDocument/definition Response: Location https://microsoft.github.io/language-server-protocol/overview
  10. ઃఆ Language Server : solargraph Client Package : eglot EmacsͰLSPΛ׆༻ͯ͠ΈΔ

    (https://qiita.com/blue0513/items/acc962738c7f4da26656) https://github.com/joaotavora/eglot https://github.com/castwide/solargraph Step1. Install Language Server Step2. Edit init.el $ gem install solargraph (add-hook 'ruby-mode-hook 'eglot-ensure)
  11. ͓·͚ ~ Rails ͷิ׬ ~ $ yard gems $ solargraph

    config 3. `.solargraph.yml` Λฤू 2. `.solargraph.yml` Λੜ੒ 1. Installed gem ʹ document ੜ੒ https://github.com/castwide/solargraph/issues/87
  12. Emacs Ͱ LSP Λࢼͨ͠ײ૝ ‣ ิ׬ɾఆٛࢀরɾࢀরݕࡧ͸͔ͳΓߴϨϕϧ ‣ Good Point ‣

    Problematic Point ‣ ಋೖ͕ͱͯ΋खܰ ‣ େن໛ϓϩδΣΫτͩͱগ͠ಈ࡞͕ॏ͍ ‣ খن໛ϓϩδΣΫτͳΒߴ଎ಈ࡞ ‣ Language Server & Client ͕܈༤ׂڌ
  13. ࠷ޙʹ ‣ LSP ͸ੌ͍ ‣ Emacs ͸ੌ͍ ‣ Ruby Project

    Ͱ΋ิ׬΍ఆٛࢀরΛ࣮ߦ ‣ εϐʔυײ͋;ΕΔ։ൃʢΫϥΠΞϯταΠυ΋܈༤ׂڌʣ ‣ LSP ͷ **ྗ** ΛआΓͯ V̋Cőe ʹ΋ෛ͚ͳ͍ิ׬ೳྗ ‣ 3rd party ੡ͷ࿈ܞϥΠϒϥϦΛಠࣗ։ൃͰ͖Δ LSP ͱ Emacs ͸͍͍ͧ