Giter Site home page Giter Site logo

ruby-syntax-tree / vscode-syntax-tree Goto Github PK

View Code? Open in Web Editor NEW
39.0 39.0 6.0 1.64 MB

VSCode support for the syntax_tree gem

Home Page: https://marketplace.visualstudio.com/items?itemName=ruby-syntax-tree.vscode-syntax-tree

License: MIT License

TypeScript 100.00%

vscode-syntax-tree's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar kddnewton avatar petercopter avatar ryanb avatar xeger avatar xfalcox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

vscode-syntax-tree's Issues

[question] - Issue with language server

Hi Syntax Tree,

Heard about you on Remote Ruby, getting below after I installed the gem.

Ruby 2.5.0

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, ...)
                           ^~~

Ruby 2.7.4

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.

Ruby 3.0.0

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

`stopLanguageServer()` hangs, preventing Stop/Restart from working correctly

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?

Feature Request: Format the Gemfile

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.

error launching language server

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

Provide a clearer error message when the `stree` exe cannot be spawned

STR:

  1. Install this extension, but without installing the gem. (And/or without having a ruby interpreter in your path.)
  2. Open a Ruby source file

Outcome: useful but slightly cryptic error messages.
image
These are fine, but could possibly be improved.

Desired:

  • Human-readable error message & maybe some actionable advice ("install the gem" "install a Ruby")
  • Maybe we could even prompt the user to install the system gem for them, as the Solargraph extension does. This is getting awfully fancy however.

HAML support doesn't seem to be working correctly

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?

Toggle bracket decorators

I would like the ability to disable the "implied bracket" decoration:

CleanShot 2022-10-20 at 10 35 22

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.

Update version in VSCode marketplace?

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?

Extension is adding "decorations" around binary ops

I'm not sure what to call these other than "decorations", but I'm now seeing this around some uses of || and -:
Screenshot 2022-12-23 at 1 08 13 AM
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.

VSCode does not pick up `stree`

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.

image
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.

Find & Replace doesn't finish

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.

plug and play?

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?

Need a way to control the language server configuration

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?

v0.3.1 from marketplace doesn't work on Linux

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.

support for format selection OR formatOnSaveMode

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?

Launches atlassian Sourcetree.app (naming collision)

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

Ignore Files setting and `--ignore-files` in `.streerc` both have no effect

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.

  • Ignore Files set to db/schema.rb
  • Ignore Files set to schema.rb
  • Ignore Files set to **/schema.rb
  • Ignore Files set to '**/schema.rb' (quoted to avoid shell expansion)
  • Ignore Files set to /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.

Extension doesn't work after install

Users on Linux and MacOS are reporting that the extension doesn't work after install:

Steps to reproduce

  1. Install from marketplace
  2. Open Command Palette
  3. Pick "Syntax Tree: Start"
  4. Get error popup

Linux
image

Mac
image

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.