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
770
GitHub の README をいい感じにする / Cool Readme
blue0513
3
1.6k
Emacs × Sound やってみた / Emacs with Sound
blue0513
1
940
Slack を TweetDeck にしてみた件 / slackdeck-proto
blue0513
0
2.8k
知ってるとお得な iTerm2 と zsh/bash の小技
blue0513
2
780
Other Decks in Programming
See All in Programming
Contemporary Test Cases
maaretp
0
140
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
340
RubyLSPのマルチバイト文字対応
notfounds
0
120
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.7k
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
200
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
230
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
110
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
300
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.8k
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
2k
Featured
See All Featured
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
Statistics for Hackers
jakevdp
796
220k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
430
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
How to train your dragon (web standard)
notwaldorf
88
5.7k
We Have a Design System, Now What?
morganepeng
50
7.2k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Designing the Hi-DPI Web
ddemaree
280
34k
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