ruby-syntax-tree / vscode-syntax-tree Goto Github PK
View Code? Open in Web Editor NEWVSCode support for the syntax_tree gem
Home Page: https://marketplace.visualstudio.com/items?itemName=ruby-syntax-tree.vscode-syntax-tree
License: MIT License
VSCode support for the syntax_tree gem
Home Page: https://marketplace.visualstudio.com/items?itemName=ruby-syntax-tree.vscode-syntax-tree
License: MIT License
Hi Syntax Tree,
Heard about you on Remote Ruby, getting below after I installed the gem.
Ruby Version: 2.5.0
VS Code: Version: 1.66.0 (Universal)
Starting language server...
No bundled syntax_tree, running global stree.
/Users/chriswade/.asdf/installs/ruby/2.5.0/lib/ruby/gems/2.5.0/gems/syntax_tree-2.0.1/lib/syntax_tree.rb:8:in `require_relative': /Users/chriswade/.asdf/installs/ruby/2.5.0/lib/ruby/gems/2.5.0/gems/syntax_tree-2.0.1/lib/syntax_tree/formatter.rb:12: syntax error, unexpected ... (SyntaxError)
def initialize(source, ...)
^~~
Starting language server...
No bundled syntax_tree, running global stree.
/Users/chriswade/.asdf/installs/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/syntax_tree-2.0.1/lib/syntax_tree/language_server.rb:28: warning: Pattern matching is experimental, and the behavior may change in future versions of Ruby!
/Users/chriswade/.asdf/installs/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/syntax_tree-2.0.1/lib/syntax_tree/language_server/inlay_hints.rb:69: warning: Pattern matching is experimental, and the behavior may change in future versions of Ruby!
Requesting implicits
Requesting implicits
/Users/chriswade/.asdf/installs/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/syntax_tree-2.0.1/lib/syntax_tree/language_server.rb:54:in `run': Unhandled: {:jsonrpc=>"2.0", :id=>1, :method=>"syntaxTree/implicits", :params=>{:textDocument=>{:uri=>"file:///Users/chriswade/Exercism/ruby/sieve/sieve.rb"}}} (RuntimeError)
from /Users/chriswade/.asdf/installs/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/syntax_tree-2.0.1/lib/syntax_tree/cli.rb:187:in `run'
from /Users/chriswade/.asdf/installs/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/syntax_tree-2.0.1/exe/stree:9:in `<top (required)>'
from /Users/chriswade/.asdf/installs/ruby/2.7.4/bin/stree:25:in `load'
from /Users/chriswade/.asdf/installs/ruby/2.7.4/bin/stree:25:in `<main>'
[Info - 9:43:20 am] Connection to server got closed. Server will restart.
Starting language server...
No bundled syntax_tree, running global stree.
Requesting implicits
/Users/chriswade/.asdf/installs/ruby/3.0.0/lib/ruby/gems/3.0.0/gems/syntax_tree-2.0.1/lib/syntax_tree/language_server.rb:54:in `run': Unhandled: {:jsonrpc=>"2.0", :id=>1, :method=>"syntaxTree/implicits", :params=>{:textDocument=>{:uri=>"file:///Users/chriswade/code/oe-qikpac-monitor/app/models/account_record.rb"}}} (RuntimeError)
from /Users/chriswade/.asdf/installs/ruby/3.0.0/lib/ruby/gems/3.0.0/gems/syntax_tree-2.0.1/lib/syntax_tree/cli.rb:187:in `run'
from /Users/chriswade/.asdf/installs/ruby/3.0.0/lib/ruby/gems/3.0.0/gems/syntax_tree-2.0.1/exe/stree:9:in `<top (required)>'
from /Users/chriswade/.asdf/installs/ruby/3.0.0/bin/stree:23:in `load'
from /Users/chriswade/.asdf/installs/ruby/3.0.0/bin/stree:23:in `<main>'
[Info - 9:51:50 am] Connection to server got closed. Server will restart.
Thanks for putting this out :)
Regards,
Chris
Whenever I use the "Syntax Tree: Stop" command on my system, the await languageClient.stop()
never returns. I've verified that the ruby process disappears from ps
output, so it there's sort of unclean shutdown happening in the language server client (provided by VS Code).
After debugging, I isolated the root cause: the VS Code client expects a response to every RPC, including shutdown. The syntax_tree
gem was abruptly terminating on shutdown requests without providing a response.
I have a proposed fix in the gem that responds to shutdown requests & verified this makes VS Code happy.
This fix reveals another issue: because Visualize
registers a command every time it is constructed, VS Code throws an error if the language server is started a second time! It might be a bug for us to (re)register the command inside startLanguageServer
-- we need a proxy command function that will forward to the most recently constructed instance of Visualize
.
My goal is to be able to cleanly restart the language server -- because I want to add settings to the extension and ensure the LSP restarts when settings are tweaked; see #3. Seems like fixing the LSP in the gem is the first step to that, although I need to fix the command-reregistration issue too, if I'm going to make settings work.
Thoughts?
Looks like we can leverage https://github.com/marketplace/actions/publish-vs-code-extension to automate updating the extension.
Would it be within the scope of syntax_tree to format the Gemfile? I swear at one point prettier-ruby was doing it, but I could be going crazy.
I'm not sure since which version, but anyway I have the syntax_tree-3.6.1 gem installed and the extension keeps complaining
Starting language server: 0 lsp --plugins=plugin/single_quotes --print-width=200
[Error - 1:37:02 PM] Syntax Tree client: couldn't create connection to server.
Launching server using command 0 failed. Error: spawn 0 ENOENT
% which stree
/Users/kain/.rvm/gems/ruby-3.0.0/bin/stree
echo $PATH
/Users/kain/.rvm/gems/ruby-3.0.0/bin:/Users/kain/.rvm/gems/ruby-3.0.0@global/bin:/Users/kain/.rvm/rubies/ruby-3.0.0/bin:etcetcetc
STR:
Outcome: useful but slightly cryptic error messages.
These are fine, but could possibly be improved.
Desired:
I think I've got things setup correctly for HAML formatting. I've got both syntax_tree
and syntax_tree-haml
installed, and I've got the VSCode extension setup with HAML as a plugin.
I'm seeing this in the output, so it looks like things are running:
Starting language server: bundle exec stree lsp --plugins=plugin/single_quotes,haml --print-width=80
However I'm not seeing HAML being reformatted on save, and when I try to Format Document
from the command palette I see
There is no formatter for 'haml' files installed.
I saw this: #39
So it seems like maybe syntax_tree needs to register as a HAML formatter?
I would like the ability to disable the "implied bracket" decoration:
As an aside, I cannot for the life of me figure out what the token name is for these decorations. As you can see, my theme shows them with a red background which is annoying, but after going through all the configurable theme colors, I can't find which one applies to these tokens. And because they don't actually exist in the document, the "inspect editor tokens and scopes" tool doesn't let me select them to determine how to style them.
The current one was last updated in April and it doesn't work for me.
Compiling manually from main
branch (after fixing a dependency version) and installing the resulting VSIX manually makes it work.
Can we get the updated one in the marketplace?
I'm not sure what to call these other than "decorations", but I'm now seeing this around some uses of ||
and -
:
They disappear when I disable this extension. I call them "decorations" because they're not in the file, only part of the editor. They only started appearing since the last update. I'd like to at least have some setting to disable them.
Hi, I'm trying to set up our project to use syntax_tree
for Ruby code formatting, and I'm having some trouble getting the VSCode extension to consistently pick up the stree
executable. If I launch VSCode using the CLI tool (eg. code .
) or using the .code-workspace
file in our project it all works correctly.
However, if I just launch VSCode directly from the OS (macOS Ventura in this case), I get the following error messages and code formatting does not work.
Starting language server: stree lsp
[Error - 3:09:05 PM] Syntax Tree client: couldn't create connection to server.
Launching server using command stree failed. Error: spawn stree ENOENT
syntax_tree
is installed in the bundle for the application and also globally. I use asdf
for managing Ruby versions on my machine.
If I click on the "Install Gem" button I get an error about permissions:
Error installing gem: Error: Command failed: gem install syntax_tree
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.
This suggests that it's trying to install the gem for the system Ruby version rather than the version of Ruby selected by asdf
.
If I do Find & Replace on a large project, it sometimes misses replacing some of the matches. When I disable the Syntax Tree extension it works without issue.
My theory is VS Code is formatting the file after each replace and there's a race condition causing the formatted code to override the following replacement in the same file. I can do more testing to verify this if needed.
I haven't noticed this with other formatters such as Prettier.
Please consider publishing the package on https://open-vsx.org/ (the opensource alternative store for VS Code compatible editors).
More info here: https://www.eclipse.org/legal/open-vsx-registry-faq/ and instructions on how to publish: https://github.com/eclipse/openvsx/wiki/Publishing-Extensions#how-to-publish-an-extension
hello,
I installed the extension, which prompted to install syntax_tree
gem, done and the Syntax Tree logs shows Starting language server: stree lsp --print-width=80
with no errors so I guess something is running.
but how to actually format Ruby files? I disabled my previous prettier format on save but I can't find instructions if there's something to configure, because actually on save it does nothing.
any way I can help tracking down the issue?
My goal is to choose which syntax_tree plugins the LSP should use when formatting my code. I'm fed up with rebornix.ruby
and would much rather use vscode-syntax-tree
plus syntax_tree
-- but I need to be able to configure the thing to match my coding standard.
This proposal adds some straightforward configuration, but it turns out that stree lsp
doesn't bother to parse options, hence my proposed fix in the syntax_tree repo, which this proposal depends on.
Thoughts on this whole scheme?
Installing latest version from the VSCode marketplace doesn't work and fail on Linux:
Activating extension 'ruby-syntax-tree.vscode-syntax-tree' failed: Cannot find module './Visualize'
Require stack:
- /home/user/.vscode-oss/extensions/ruby-syntax-tree.vscode-syntax-tree-0.3.1/out/extension.js
- /usr/lib/code/out/vs/loader.js
- /usr/lib/code/out/bootstrap-amd.js
- /usr/lib/code/out/bootstrap-fork.js.
Analyzing the package from https://marketplace.visualstudio.com/_apis/public/gallery/publishers/ruby-syntax-tree/vsextensions/vscode-syntax-tree/0.3.1/vspackage and extracting it to a folder makes the error pretty clear:
~/Downloads/vscode-ruby-syntax-tree-v0.3.1 tree extension/out
├── debounce.js
├── Disasm.js
├── extension.js
├── ImplicitParentheses.js
├── Implicits.js
├── InlayHints.js
├── isualize.js
├── startClient.js
├── startLanguageClient.js
└── visualize.js
0 directories, 10 files
~/Downloads/vscode-ruby-syntax-tree-v0.3.1 grep Visualize extension/out/extension.js
const Visualize_1 = require("./Visualize");
See the capital V on the require version the lower case v on the actual file on the VSIX from the marketplace.
I can't reproduce this issue when compiling and packaging the extension on Linux with:
yarn install --frozen-lockfile
yarn compile
yarn package
Maybe it was packaged in a case-insensitive OS? No idea...
If you manually go into /home/user/.vscode-oss/extensions/ruby-syntax-tree.vscode-syntax-tree-0.3.1/out/extension.js
and edit line as
- const Visualize_1 = require("./Visualize");
+ const Visualize_1 = require("./visualize");
it starts working fine.
I would like to format only the code I specify for some reasons related to the project that I work on.
Therefore, It would be awesome to add support for formating the code only that I select from the editor or when format on save option is enabled, formatOnSaveMode: "modifications" also would prove very useful to me.
Is there any chance to adding one of these?
On my system, there is a binary present called stree
which is for opening the sourcetree app. I know this app has been around for quite some time, and this isn't an invention of mine. I'm just imagining that there might be a lot of people with an stree
binary already on their system.
Upon installing the app, it opened up the sourcetree app in five different directories on my system. I'm wondering if there's some way to detect the appropriate binary by default?
I've gotten it working by manually configuring the path to the gem, and it seems to be great! I just don't want this naming collision to possibly hamper adoption.
Thanks so much!
Cory
This may be due to a limitation of the language server itself, but I cannot get the extension to ignore files.
Assume I want to ignore checking and formatting for the file db/schema.rb
in my Rails project. With the following .streerc
file in the project root:
--ignore-files='db/schema.rb'
I can successfully have the CLI and Rake tasks ignore the file. However, the extension will always format the file, which is annoying because I like to use Format On Save. The language server does seem to pick up my other settings in .streerc
, however.
Here's what I have tried. In each case I have restarted the language server. Also, it may be worth noting I am using a bundled syntax_tree
.
db/schema.rb
schema.rb
**/schema.rb
'**/schema.rb'
(quoted to avoid shell expansion)/Users/chase/dev/my_project/db/schema.rb
(Absolute path)I expect the extension to do nothing when asked to format an ignored file either directly with the Command Pallete or with Format On Save.
If I need to dive into the language server and extension code to debug this, I will, because currently it's a bit annoying. I plan to generate a "TODO" list of files that fail stree check
and adding them to my .streerc
, so I can incrementally format my project.
Users on Linux and MacOS are reporting that the extension doesn't work after install:
VSCode DevTools shows:
Linux
mainThreadExtensionService.ts:111 Activating extension 'ruby-syntax-tree.vscode-syntax-tree' failed: Cannot find module 'semver/functions/parse'
Require stack:
- /home/user/.vscode/extensions/ruby-syntax-tree.vscode-syntax-tree-0.3.0/node_modules/vscode-languageclient/lib/node/main.js
- /home/user/.vscode/extensions/ruby-syntax-tree.vscode-syntax-tree-0.3.0/node_modules/vscode-languageclient/node.js
- /home/user/.vscode/extensions/ruby-syntax-tree.vscode-syntax-tree-0.3.0/out/extension.js
- /opt/visual-studio-code/resources/app/out/vs/loader.js
- /opt/visual-studio-code/resources/app/out/bootstrap-amd.js
- /opt/visual-studio-code/resources/app/out/bootstrap-fork.js.
$onExtensionActivationError @ mainThreadExtensionService.ts:111
Mac
Activating extension 'ruby-syntax-tree.vscode-syntax-tree' failed: Cannot find module 'semver/functions/parse'
Require stack:
- /Users/user/.vscode/extensions/ruby-syntax-tree.vscode-syntax-tree-0.3.0/node_modules/vscode-languageclient/lib/node/main.js
- /Users/user/.vscode/extensions/ruby-syntax-tree.vscode-syntax-tree-0.3.0/node_modules/vscode-languageclient/node.js
- /Users/user/.vscode/extensions/ruby-syntax-tree.vscode-syntax-tree-0.3.0/out/extension.js
- /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js
- /Applications/Visual Studio Code.app/Contents/Resources/app/out/bootstrap-amd.js
- /Applications/Visual Studio Code.app/Contents/Resources/app/out/bootstrap-fork.js.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.