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
770
Other Decks in Programming
See All in Programming
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
4
640
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.4k
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
160
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
860
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
エンジニアとして関わる要件と仕様(公開用)
murabayashi
0
280
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
Click-free releases & the making of a CLI app
oheyadam
2
110
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
52
13k
[RailsConf 2023] Rails as a piece of cake
palkan
52
4.9k
Designing for humans not robots
tammielis
250
25k
Become a Pro
speakerdeck
PRO
25
5k
Visualization
eitanlees
145
15k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
How STYLIGHT went responsive
nonsquared
95
5.2k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Six Lessons from altMBA
skipperchong
27
3.5k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
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