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

LSP の力を使って Ruby する!

Taiju Aoki
January 29, 2019

LSP の力を使って Ruby する!

Taiju Aoki

January 29, 2019
Tweet

More Decks by Taiju Aoki

Other Decks in Programming

Transcript

  1. Who Am I ‣ ΤϜεϦʔגࣜձࣾ Ͱ Ϋϥ΢υిࢠΧϧς Λ։ൃ blue (@blue_1617)

    ‣ Ruby, JavaScript, Scala etc Λ׆༻ https://blue0513.github.io/show_room/ ‣ Emacs ޷͖ͷΤϯδχΞ 2 ࠷ۙͷ LT ͱ͔ ‣ Emacs Ͱ LSP Λ࢖ͬͯΈͨΑ ‣ Emacs Ͱ Web αʔϏεΛ։ൃͯ͠8ϲ݄͕ܦͪ·ͨ͠ ‣ 2018೥Ͱ΋ʢԶ͸ʣEmacs Λ࢖͍͍ͨ ‣ VTuber ͬͯ஌ͬͯ·͢ʁ ‣ VTuber Λࢧ͑Δٕज़ ۙگͱ͔ ‣ ౬ͨΜΆΛങͬͯշ຾ͯ͠Δ (´ɾωɾ`)
  2. Who Am I ‣ ΤϜεϦʔגࣜձࣾ Ͱ Ϋϥ΢υిࢠΧϧς Λ։ൃ blue (@blue_1617)

    ‣ Ruby, JavaScript, Scala etc Λ׆༻ https://blue0513.github.io/show_room/ ‣ Emacs ޷͖ͷΤϯδχΞ 3 ࠷ۙͷ LT ͱ͔ ‣ Emacs Ͱ LSP Λ࢖ͬͯΈͨΑ ‣ Emacs Ͱ Web αʔϏεΛ։ൃͯ͠8ϲ݄͕ܦͪ·ͨ͠ ‣ 2018೥Ͱ΋ʢԶ͸ʣEmacs Λ࢖͍͍ͨ ‣ VTuber ͬͯ஌ͬͯ·͢ʁ ‣ VTuber Λࢧ͑Δٕज़ ۙگͱ͔ ‣ ౬ͨΜΆΛങͬͯշ຾ͯ͠Δ (´ɾωɾ`) We are Hiring !! M3, Inc.
  3. 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
  4. 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 ΤσΟλͱ͔ 8
  5. 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 ιʔείʔυͷղੳΛͯ͘͠ΕΔαʔό ʢϩʔΧϧʹཱͯΒΕΔʣ 9
  6. 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) 11
  7. 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 12
  8. LSPͱ͸ʁ Language Server Protocol (LSP) ͱ͸..... ݴޠͷղੳͳͲΛߦ͏ Language Server ͱ֤πʔϧʢClientʣ͕

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

    ௨৴ɾ࿈ܞ͢ΔࡍͷϓϩτίϧΛنఆ͢Δ΋ͷ ‣ ֤πʔϧ͸ Language Server ͕ͲͷݴޠΛѻ͍ͬͯΔ͔Λҙࣝ͢ Δ͜ͱͳ͘ɺิ׬΍ఆٛࢀরΛߦ͑Δ ϝϦοτ͸..... https://microsoft.github.io/language-server-protocol/ ‣ Emacs ౳ͷΤσΟλͷ ิ׬ɾఆٛࢀরೳྗ౳͕޲্ ͢Δ LSP Ͱ Ruby ͷิ׬͕ڧ͘ͳΔʂ 14
  10. 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 15
  11. ઃఆ 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) 17
  12. ͓·͚ ~ Rails ͷิ׬ ~ $ yard gems $ solargraph

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

    Problematic Point ‣ ಋೖ͕ͱͯ΋खܰ ‣ େن໛ϓϩδΣΫτͩͱগ͠ಈ࡞͕ॏ͍ ‣ খن໛ϓϩδΣΫτͳΒߴ଎ಈ࡞ ‣ Language Server & Client ͕܈༤ׂڌ 29
  14. ࠷ޙʹ ‣ LSP ͸ੌ͍ ‣ Ruby Project Ͱ΋ิ׬΍ఆٛࢀরΛ࣮ߦ ‣ εϐʔυײ͋;ΕΔ։ൃʢLanguage

    Server & Clientʣ LSP Ͱ Ruby ָ͕ʹʂ ‣ ֎෦ gem ͷఆٛࢀর΋ OKʂ ‣ ඪ४ϝιουҎ֎ͷิ׬΋ OKʂ ‣ Rails ͷαϙʔτ΋ॆ࣮ ‣ Emacs ΍ Vim ౳ͷΤσΟλͰ΋շదʹ Ruby ͕ॻ͚Δ 30