LSP の力を使って Ruby する!

4cae187d836abc4428abdfb9cd448098?s=47 Taiju Aoki
January 29, 2019

LSP の力を使って Ruby する!

4cae187d836abc4428abdfb9cd448098?s=128

Taiju Aoki

January 29, 2019
Tweet

Transcript

  1. LSP ͷྗΛ࢖ͬͯ Ruby ͢Δʂ @blue_1617

  2. 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 Λࢧ͑Δٕज़ ۙگͱ͔ ‣ ౬ͨΜΆΛങͬͯշ຾ͯ͠Δ (´ɾωɾ`)
  3. 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.
  4. ࣄͷൃ୺ ~ LSP ͕ੌ͍ͱฉ͍ͯ ~ Emacs Ͱ Ruby ॻ͍ͯΔͱ ิ׬ͱ͔ఆٛࢀরͭΒ͘ͳ͍....ʁ

    ʮRuby ͷؾ͕࣋ͪղΒͳ͍.....ʯ ʮิ׬Ͱ͖ͳ͍.....ʯ 4
  5. LSP Λ࢖͏ͱิ׬͕ڧ͘ͳΔʂʁ LSP ʮRuby ͷؾ͕࣋ͪ෼͔Δʂʯ ʮิ׬͕Ͱ͖ΔɺͰ͖Δͧʂʯ ࣄͷൃ୺ ~ LSP ͕ੌ͍ͱฉ͍ͯ

    ~ 5
  6. LSP Λ࢖͏ͱิ׬͕ڧ͘ͳΔʂʁ LSP ʮRuby ͷؾ͕࣋ͪ෼͔Δʂʯ ʮิ׬͕Ͱ͖ΔɺͰ͖Δͧʂʯ ࣄͷൃ୺ ~ LSP ͕ੌ͍ͱฉ͍ͯ

    ~ LSP Ͱ Ruby ͷิ׬ΛڧԽ͍ͨ͠ʂ 6
  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 7
  8. 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
  9. 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
  10. LSPͱ͸ʁ https://microsoft.github.io/language-server-protocol/implementors/servers/ ݴޠ͝ͱͷ Language Server ʢ܈༤ׂڌͳঢ়ଶʣ 10

  11. 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
  12. 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
  13. LSPͱ͸ʁ Language Server Protocol (LSP) ͱ͸..... ݴޠͷղੳͳͲΛߦ͏ Language Server ͱ֤πʔϧʢClientʣ͕

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

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

  17. ઃఆ 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
  18. ิ׬ ‣ String.class ͳΒɺto_i ͕αδΣετ͞ΕΔ ‣ Array.class ͳΒɺto_h ͕αδΣετ͞ΕΔ 18

  19. ิ׬ ‣ String.class ͳΒɺto_i ͕αδΣετ͞ΕΔ ‣ Array.class ͳΒɺto_h ͕αδΣετ͞ΕΔ ಈը

    19
  20. ิ׬ ‣ Πϯελϯεϝιου ΋αδΣετ͞ΕΔ ‣ `Subscription#to_param` ΛαδΣετ 20

  21. ิ׬ ‣ Πϯελϯεϝιου ΋αδΣετ͞ΕΔ ‣ `Subscription#to_param` ΛαδΣετ ಈը 21

  22. ఆٛࢀর 22

  23. ఆٛࢀর `Subscription.confirm` ʹఆٛδϟϯϓ͢Δʂ ಈը 23

  24. ࢀরݕࡧ 'Subscription.confirm' ͷࢀরՕॴΛݕࡧ͢Δʂ 24

  25. ࢀরݕࡧ ಈը 25

  26. ͓·͚ ~ Rails ͷิ׬ ~ $ yard gems $ solargraph

    config 3. `.solargraph.yml` Λฤू 2. `.solargraph.yml` Λੜ੒ 1. Installed gem ʹ document ੜ੒ https://github.com/castwide/solargraph/issues/87 26
  27. ͓·͚ ~ Rails ͷิ׬ ~ `ActiveRecord` ͳͲ͕ީิͱͯ͠αδΣετ͞ΕΔʂ 27

  28. ͓·͚ ~ Rails ͷิ׬ ~ `ActiveRecord` ͳͲ͕ީิͱͯ͠αδΣετ͞ΕΔʂ LSP Ͱշదͳ Ruby

    ίʔσΟϯά 28
  29. Ruby Ͱ LSP Λࢼͨ͠ײ૝ ‣ ิ׬ɾఆٛࢀরɾࢀরݕࡧ͸͔ͳΓߴϨϕϧ ‣ Good Point ‣

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

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