Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
LSP の力を使って Ruby する!
Search
Taiju Aoki
January 29, 2019
Programming
0
1.8k
LSP の力を使って Ruby する!
Slide for Megro.rb #23
https://megurorb.connpass.com/event/115497/
Taiju Aoki
January 29, 2019
Tweet
Share
More Decks by Taiju Aoki
See All by Taiju Aoki
本番運用中 Oracle を破壊してしまった話 ~ 破壊と創世 ~ / Oracle Destruction and Creation
blue0513
0
2.8k
オンプレ to オンプレした話/on-premises2on-premises
blue0513
0
2.8k
GitもCIもテストもないプロジェクトでデプロイを自動化するまでの道 / rebuild of DevOps
blue0513
0
3k
Git & GitLab & コードレビューって? / about Git, GitLab, CodeReview
blue0513
0
210
ElectronでSlackをさらに便利にしちゃう / Slack with Electron
blue0513
3
790
GitHub の README をいい感じにする / Cool Readme
blue0513
3
1.6k
Emacs × Sound やってみた / Emacs with Sound
blue0513
1
950
Slack を TweetDeck にしてみた件 / slackdeck-proto
blue0513
0
2.8k
知ってるとお得な iTerm2 と zsh/bash の小技
blue0513
2
790
Other Decks in Programming
See All in Programming
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
260
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
550
103 Early Hints
sugi_0000
1
230
Exploring: Partial and Independent Composables
blackbracken
0
100
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
nekko cloudにおけるProxmox VE利用事例
irumaru
3
440
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
340
Recoilを剥がしている話
kirik
5
6.8k
テストコード書いてみませんか?
onopon
2
130
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
2
390
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
7
1.3k
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
480
Featured
See All Featured
Optimising Largest Contentful Paint
csswizardry
33
3k
Docker and Python
trallard
42
3.1k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
Optimizing for Happiness
mojombo
376
70k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
The Pragmatic Product Professional
lauravandoore
32
6.3k
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Transcript
LSP ͷྗΛͬͯ Ruby ͢Δʂ @blue_1617
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 Λࢧ͑Δٕज़ ۙگͱ͔ ‣ ౬ͨΜΆΛങͬͯշͯ͠Δ (´ɾωɾ`)
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.
ࣄͷൃ ~ LSP ͕ੌ͍ͱฉ͍ͯ ~ Emacs Ͱ Ruby ॻ͍ͯΔͱ ิͱ͔ఆٛࢀরͭΒ͘ͳ͍....ʁ
ʮRuby ͷؾ͕࣋ͪղΒͳ͍.....ʯ ʮิͰ͖ͳ͍.....ʯ 4
LSP Λ͏ͱิ͕ڧ͘ͳΔʂʁ LSP ʮRuby ͷؾ͕͔࣋ͪΔʂʯ ʮิ͕Ͱ͖ΔɺͰ͖Δͧʂʯ ࣄͷൃ ~ LSP ͕ੌ͍ͱฉ͍ͯ
~ 5
LSP Λ͏ͱิ͕ڧ͘ͳΔʂʁ LSP ʮRuby ͷؾ͕͔࣋ͪΔʂʯ ʮิ͕Ͱ͖ΔɺͰ͖Δͧʂʯ ࣄͷൃ ~ LSP ͕ੌ͍ͱฉ͍ͯ
~ LSP Ͱ Ruby ͷิΛڧԽ͍ͨ͠ʂ 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 (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
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
LSPͱʁ https://microsoft.github.io/language-server-protocol/implementors/servers/ ݴޠ͝ͱͷ Language Server ʢ܈༤ׂڌͳঢ়ଶʣ 10
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
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
LSPͱʁ Language Server Protocol (LSP) ͱ..... ݴޠͷղੳͳͲΛߦ͏ Language Server ͱ֤πʔϧʢClientʣ͕
௨৴ɾ࿈ܞ͢ΔࡍͷϓϩτίϧΛنఆ͢Δͷ ‣ ֤πʔϧ Language Server ͕ͲͷݴޠΛѻ͍ͬͯΔ͔Λҙࣝ͢ Δ͜ͱͳ͘ɺิఆٛࢀরΛߦ͑Δ ϝϦοτ..... https://microsoft.github.io/language-server-protocol/ ‣ Emacs ͷΤσΟλͷ ิɾఆٛࢀরೳྗ্͕ ͢Δ 13
LSPͱʁ Language Server Protocol (LSP) ͱ..... ݴޠͷղੳͳͲΛߦ͏ Language Server ͱ֤πʔϧʢClientʣ͕
௨৴ɾ࿈ܞ͢ΔࡍͷϓϩτίϧΛنఆ͢Δͷ ‣ ֤πʔϧ Language Server ͕ͲͷݴޠΛѻ͍ͬͯΔ͔Λҙࣝ͢ Δ͜ͱͳ͘ɺิఆٛࢀরΛߦ͑Δ ϝϦοτ..... https://microsoft.github.io/language-server-protocol/ ‣ Emacs ͷΤσΟλͷ ิɾఆٛࢀরೳྗ্͕ ͢Δ LSP Ͱ Ruby ͷิ͕ڧ͘ͳΔʂ 14
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
Demo (Emacs & LSP) 16
ઃఆ 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
ิ ‣ String.class ͳΒɺto_i ͕αδΣετ͞ΕΔ ‣ Array.class ͳΒɺto_h ͕αδΣετ͞ΕΔ 18
ิ ‣ String.class ͳΒɺto_i ͕αδΣετ͞ΕΔ ‣ Array.class ͳΒɺto_h ͕αδΣετ͞ΕΔ ಈը
19
ิ ‣ Πϯελϯεϝιου αδΣετ͞ΕΔ ‣ `Subscription#to_param` ΛαδΣετ 20
ิ ‣ Πϯελϯεϝιου αδΣετ͞ΕΔ ‣ `Subscription#to_param` ΛαδΣετ ಈը 21
ఆٛࢀর 22
ఆٛࢀর `Subscription.confirm` ʹఆٛδϟϯϓ͢Δʂ ಈը 23
ࢀরݕࡧ 'Subscription.confirm' ͷࢀরՕॴΛݕࡧ͢Δʂ 24
ࢀরݕࡧ ಈը 25
͓·͚ ~ Rails ͷิ ~ $ yard gems $ solargraph
config 3. `.solargraph.yml` Λฤू 2. `.solargraph.yml` Λੜ 1. Installed gem ʹ document ੜ https://github.com/castwide/solargraph/issues/87 26
͓·͚ ~ Rails ͷิ ~ `ActiveRecord` ͳͲ͕ީิͱͯ͠αδΣετ͞ΕΔʂ 27
͓·͚ ~ Rails ͷิ ~ `ActiveRecord` ͳͲ͕ީิͱͯ͠αδΣετ͞ΕΔʂ LSP Ͱշదͳ Ruby
ίʔσΟϯά 28
Ruby Ͱ LSP Λࢼͨ͠ײ ‣ ิɾఆٛࢀরɾࢀরݕࡧ͔ͳΓߴϨϕϧ ‣ Good Point ‣
Problematic Point ‣ ಋೖ͕ͱͯखܰ ‣ େنϓϩδΣΫτͩͱগ͠ಈ࡞͕ॏ͍ ‣ খنϓϩδΣΫτͳΒߴಈ࡞ ‣ Language Server & Client ͕܈༤ׂڌ 29
࠷ޙʹ ‣ LSP ੌ͍ ‣ Ruby Project ͰิఆٛࢀরΛ࣮ߦ ‣ εϐʔυײ͋;ΕΔ։ൃʢLanguage
Server & Clientʣ LSP Ͱ Ruby ָ͕ʹʂ ‣ ֎෦ gem ͷఆٛࢀর OKʂ ‣ ඪ४ϝιουҎ֎ͷิ OKʂ ‣ Rails ͷαϙʔτॆ࣮ ‣ Emacs Vim ͷΤσΟλͰշదʹ Ruby ͕ॻ͚Δ 30