You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have checked that this feature is not already implemented
This feature does not exist
Use case
Slim is a fairly popular choice among ruby/rails devs and adding support for it is actually not a lot of work once ERB support is merged
Description
Ruby intellisense for slim printing lines, none-printing lines and ruby code blocks
ruby:
print_msg = true
- if print_msg
= 'hello world'.capitalize
Implementation
Following the same Idea in issue#1055 the LSP can require slim gem from the main bundle and provide the feature only if it's found
As for parsing slim, The lsp doesn't have to worry about that!
instead it can use Slim::ERBConverter.new(options).call(slim_code) which outputs erb code
Reacted by Andre Meij, Janko Marohnić, Christoph Blessing, Michael Khabarov, arthurbryant, Daniil Danilin, Sergei Malykh, Ermolaev Andrey, Ivan Korolev, Artur Rajski and 3 more
@vinistock can you assign me this issue?
I would like to take a swing at implementing it once #1184 and Shopify/vscode-ruby-lsp#896 are merged if that's ok!
and do you have any feedbacks on my suggested approach?
Thank you for the feature suggestion. Does Slim provide a way to extract just the Ruby code while maintaining the correct line and column information?
Ideally, we wouldn't be converting Slim into ERB and then ERB into Ruby, so that we can finally parse the Ruby code. That will be very slow for large files.
That is currently the biggest blocker with ERB support and we can't move forward until we figure that part out.
The slim gem ships a parses but it doesn't give the line numbers, however it gives a syntax tree in the form of a nested array
so the following example
ruby:
print_value =true- if print_value
p='Hello World'.capatlize
would generate this output when put through the slim parser
I don't believe that AST will allow using Ruby LSP features. All of our features are based on parsing Ruby with Prism and analyzing the AST.
For that to work properly, we need slim to be able to extract only the Ruby code from templates maintaining their exact line and column positions.
Otherwise, things like semantic highlighting would highlight the wrong range for tokens. Or definition wouldn't be able to find the target based on the position received from the editor.
We would need slim to be able to take a template like this
ruby:
print_value = true
- if print_value
p = 'Hello World'.capatlize
And return only the Ruby code in its exact positions
Then we can just take that Ruby code, parse it with Prism (which will give us the right line and column information) and all features will just work out of the box.
this is for your eyes to review its way more optimized than the traverse function! ideally I would like to add the sx-processor (I'm open to renaming it) class to the ruby-lsp and add a SlimDocument class that uses it to generate the ruby blob for Prism
Sorry, but if we were to accept a runtime dependency, it would be only implicit (like we do for rubocop) and only for slim itself.
I'm also wondering if this may be a better fit for addons. There are multiple templating engines out there and we probably don't want to maintain support for all of them inside this codebase.
It's not currently possible to do it, but I'm thinking if we might be able to design an API to allow for this.
@vinistock Apologize for the misunderstanding I didn't mean adding the gem as a runtime dependency I just meant coding the class into the LSP it self, I made the gem for demo proposes, so you can review the approach Im proposing. that being said I do see your point. Im open to both.
Hello folks - I found this issue whilst researching the root cause of why .slim isn't fully supported (beyond syntax highlighting) for Intellisense etc in VSCode - I can see we added a help-wanted label in 2025, but I haven't seen any movement since then. Keen to see which direction it could move, if at all - as full .slim VSCode support would be awesome!
I can see @omarluq has put together some example code that could potentially be used directly in Ruby-LSP (not as a dependency, as suggested), and it seems to have promise. @vinistock or other LSP contributors- Do we think a PR bringing this code into Ruby-LSP would be viable?
Re: the addons approach: I noticed the link in this comment to addons no longer works (though I did find this - is this still relevant?) - Did said pre-requisite work in addons get completed? or is this blocked by said work?
Following @vinistock's suggestion above, I've written an add-on for this: ruby-lsp-slim-lang. It reads the template with Slim's parser and keeps only the Ruby, blanking everything else, which keeps each line and column where it was in the template. Ruby LSP then handles the template much like an ERB file, with go to definition, hover and completion working inside = and - lines, ruby: blocks and #{} interpolation.
It isn't on RubyGems yet. If you'd like to try it, add it to your app's Gemfile:
In Neovim, it works today once Neovim recognises .slim files and slim is in the file types Ruby LSP is attached to. The README has the config for both.
VS Code needs a change to the extension, since it only sends Ruby and ERB files to the server. I've opened #4270 to add a rubyLsp.addonLanguageIds setting for that.
The README lists the gaps I know about. For example, it only knows Slim's default shortcuts and attribute delimiters, since Ruby LSP doesn't boot your app. I expect there are templates it gets wrong that I haven't come across. Reports from anyone with a large Slim codebase would help most. Please open an issue on the repo if something doesn't resolve or the server reports errors in a template.
The add-on API still doesn't have a way to register a document type. As such, the add-on patches Ruby LSP's document store to create its own, which depends on Ruby LSP's internals. That's why it pins ruby-lsp to >= 0.26, < 0.28.
Activity
omarluq commentedon Dec 5, 2023
@vinistock can you assign me this issue?
I would like to take a swing at implementing it once #1184 and Shopify/vscode-ruby-lsp#896 are merged if that's ok!
and do you have any feedbacks on my suggested approach?
vinistock commentedon Dec 5, 2023
Thank you for the feature suggestion. Does Slim provide a way to extract just the Ruby code while maintaining the correct line and column information?
Ideally, we wouldn't be converting Slim into ERB and then ERB into Ruby, so that we can finally parse the Ruby code. That will be very slow for large files.
That is currently the biggest blocker with ERB support and we can't move forward until we figure that part out.
omarluq commentedon Dec 5, 2023
The
slimgem ships a parses but it doesn't give the line numbers, however it gives a syntax tree in the form of a nested arrayso the following example
would generate this output when put through the slim parser
Maybe traverse the tree and derive the line numbers and column numbers for the ruby code
vinistock commentedon Dec 6, 2023
I don't believe that AST will allow using Ruby LSP features. All of our features are based on parsing Ruby with Prism and analyzing the AST.
For that to work properly, we need
slimto be able to extract only the Ruby code from templates maintaining their exact line and column positions.Otherwise, things like semantic highlighting would highlight the wrong range for tokens. Or definition wouldn't be able to find the target based on the position received from the editor.
We would need
slimto be able to take a template like thisAnd return only the Ruby code in its exact positions
Then we can just take that Ruby code, parse it with Prism (which will give us the right line and column information) and all features will just work out of the box.
omarluq commentedon Dec 7, 2023
@vinistock
slimdoesn't give us that out of the box, that being said its not really hard to derive a ruby document we just traverse the AST.omarluq commentedon Dec 7, 2023
ok so I got a little carried away and made small gem out of this traverse function https://github.com/omarluq/sx-processor
this is for your eyes to review its way more optimized than the traverse function! ideally I would like to add the
sx-processor(I'm open to renaming it) class to theruby-lspand add aSlimDocumentclass that uses it to generate the ruby blob for Prismvinistock commentedon Dec 8, 2023
Sorry, but if we were to accept a runtime dependency, it would be only implicit (like we do for rubocop) and only for
slimitself.I'm also wondering if this may be a better fit for addons. There are multiple templating engines out there and we probably don't want to maintain support for all of them inside this codebase.
It's not currently possible to do it, but I'm thinking if we might be able to design an API to allow for this.
omarluq commentedon Dec 8, 2023
@vinistock Apologize for the misunderstanding I didn't mean adding the gem as a runtime dependency I just meant coding the class into the LSP it self, I made the gem for demo proposes, so you can review the approach Im proposing. that being said I do see your point. Im open to both.
oheyjesse commentedon Mar 17, 2026
Hello folks - I found this issue whilst researching the root cause of why
.slimisn't fully supported (beyond syntax highlighting) for Intellisense etc in VSCode - I can see we added ahelp-wantedlabel in 2025, but I haven't seen any movement since then. Keen to see which direction it could move, if at all - as full.slimVSCode support would be awesome!I can see @omarluq has put together some example code that could potentially be used directly in Ruby-LSP (not as a dependency, as suggested), and it seems to have promise. @vinistock or other LSP contributors- Do we think a PR bringing this code into Ruby-LSP would be viable?
Re: the
addonsapproach: I noticed the link in this comment to addons no longer works (though I did find this - is this still relevant?) - Did said pre-requisite work in addons get completed? or is this blocked by said work?Allow sending add-on languages to the server
bjeanes commentedon Nov 11, 2026
Following @vinistock's suggestion above, I've written an add-on for this: ruby-lsp-slim-lang. It reads the template with Slim's parser and keeps only the Ruby, blanking everything else, which keeps each line and column where it was in the template. Ruby LSP then handles the template much like an ERB file, with go to definition, hover and completion working inside
=and-lines,ruby:blocks and#{}interpolation.It isn't on RubyGems yet. If you'd like to try it, add it to your app's
Gemfile:In Neovim, it works today once Neovim recognises
.slimfiles andslimis in the file types Ruby LSP is attached to. The README has the config for both.VS Code needs a change to the extension, since it only sends Ruby and ERB files to the server. I've opened #4270 to add a
rubyLsp.addonLanguageIdssetting for that.The README lists the gaps I know about. For example, it only knows Slim's default shortcuts and attribute delimiters, since Ruby LSP doesn't boot your app. I expect there are templates it gets wrong that I haven't come across. Reports from anyone with a large Slim codebase would help most. Please open an issue on the repo if something doesn't resolve or the server reports errors in a template.
The add-on API still doesn't have a way to register a document type. As such, the add-on patches Ruby LSP's document store to create its own, which depends on Ruby LSP's internals. That's why it pins
ruby-lspto>= 0.26, < 0.28.