Skip to content

Conversation

@binhtddev
Copy link
Member

@binhtddev binhtddev commented Dec 8, 2022

πŸ€” What's changed?

⚑️ What's your motivation?

Fixes #72, #79, #90, #96

🏷️ What kind of change is this?

  • πŸ› Bug fix (non-breaking change which fixes a defect)

♻️ Anything particular you want feedback on?

First, The url.pathToFileURL was introduced by #68 to fix #66 but it did not fix the problem and #66 was closed by using another product.

After that, the #73 change how language-server worked. It refactor src/wasm/startWasmServer.ts into src/wasm/startEmbeddedServer.ts and src/wasm/startStandaloneServer.ts. The startEmbeddedServer is used for VS Code with browser support and the startStandaloneServer is used as fallback for user outside of VS Code but it was not tested properly.

As a result, the language server is rendered unusable outside of VS Code, and this PR aims to rectify this issue.

πŸ“‹ Checklist:

  • I agree to respect and uphold the Cucumber Community Code of Conduct
  • I've changed the behaviour of the code
    • I have added/updated tests to cover my changes.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • Users should know about my change
    • I have added an entry to the "Unreleased" section of the CHANGELOG, linking to this pull request.

This text was originally generated from a template, then edited by hand. You can modify the template here.

@pprotas
Copy link

pprotas commented Dec 16, 2022

Can you provide a guide on how to install this branch locally for my neovim config? Seems like it takes too long for the maintainer to merge it

@speelbarrow
Copy link

This also fixes #79

@speelbarrow
Copy link

Can you provide a guide on how to install this branch locally for my neovim config? Seems like it takes too long for the maintainer to merge it

@pprotas npm i -g @binhtran432k/cucumber-language-server@1.4.0

@speelbarrow
Copy link

@binhtran432k after installing your fork from NPM I can get the language server to run without crashing immediately, but upon trying to use it with Neovim it logs the following:

Cucumber Language Server 1.4.0: Unhandled Rejection at promise: [object Promise], reason: TypeError: Failed to parse URL from /opt/homebrew/lib/node_modules/@binhtran432k/cucumber-language-server/node_modules/web-tree-sitter/tree-sitter.wasm

I added some code to log reason.stack() at line 14 in bin/cucumber-language-server.cjs and got the following output:

TypeError: Failed to parse URL from /opt/homebrew/lib/node_modules/@binhtran432k/cucumber-language-server/node_modules/web-tree-sitter/tree-sitter.wasm
  at Object.fetch (node:internal/deps/undici/undici:11522:11)"

@speelbarrow
Copy link

@binhtran432k after installing your fork from NPM I can get the language server to run without crashing immediately, but upon trying to use it with Neovim it logs the following:

Cucumber Language Server 1.4.0: Unhandled Rejection at promise: [object Promise], reason: TypeError: Failed to parse URL from /opt/homebrew/lib/node_modules/@binhtran432k/cucumber-language-server/node_modules/web-tree-sitter/tree-sitter.wasm

I added some code to log reason.stack() at line 14 in bin/cucumber-language-server.cjs and got the following output:

TypeError: Failed to parse URL from /opt/homebrew/lib/node_modules/@binhtran432k/cucumber-language-server/node_modules/web-tree-sitter/tree-sitter.wasm
  at Object.fetch (node:internal/deps/undici/undici:11522:11)"

Resolved by using Node 16

@lkoning
Copy link

lkoning commented Nov 14, 2023

hi all, thank you for your work! I tried to use your lsp-version in my Lazyvim by your instructions:

  1. Install the lsp locally - βœ…
  2. Config Lazyvim:
return {
  {
    "neovim/nvim-lspconfig",
    opts = {
      servers = {
        cucumber_language_server = {
          -- currently using a forked ls. 
          mason = false,
          root_dir = require("lspconfig.util").root_pattern("pom.xml"),
          settings = {
            cucumber = {
              features = { "**/*.feature" },
              glue = { "**/*Steps.java" },
            },
          },
        },
      },
    },
  },
}

Now, after loading my Java repo, or a JS repo...LSP seems to be active but formatting and finding stepDefs does not work. Haven't tried Vscode.

LspLog:

[START][2023-11-14 10:18:12] LSP logging initiated
[WARN][2023-11-14 10:18:12] ...lsp/handlers.lua:137	"The language server cucumber_language_server triggers a registerCapability handler despite dynamicRegistration set to false. Report upstream, this warning is harmless"
[ERROR][2023-11-14 10:18:12] ...lsp/handlers.lua:535	"Failed to reindex: Cannot read properties of undefined (reading 'reduce')"
[ERROR][2023-11-14 10:18:12] ...lsp/handlers.lua:535	"Failed to reindex: Cannot read properties of undefined (reading 'reduce')"

I don't really know what this means. At least it seems we are a few steps further.

@shlomisaad
Copy link

hi all, thank you for your work! I tried to use your lsp-version in my Lazyvim by your instructions:

  1. Install the lsp locally - βœ…
  2. Config Lazyvim:
return {
  {
    "neovim/nvim-lspconfig",
    opts = {
      servers = {
        cucumber_language_server = {
          -- currently using a forked ls. 
          mason = false,
          root_dir = require("lspconfig.util").root_pattern("pom.xml"),
          settings = {
            cucumber = {
              features = { "**/*.feature" },
              glue = { "**/*Steps.java" },
            },
          },
        },
      },
    },
  },
}

Now, after loading my Java repo, or a JS repo...LSP seems to be active but formatting and finding stepDefs does not work. Haven't tried Vscode.

LspLog:

[START][2023-11-14 10:18:12] LSP logging initiated
[WARN][2023-11-14 10:18:12] ...lsp/handlers.lua:137	"The language server cucumber_language_server triggers a registerCapability handler despite dynamicRegistration set to false. Report upstream, this warning is harmless"
[ERROR][2023-11-14 10:18:12] ...lsp/handlers.lua:535	"Failed to reindex: Cannot read properties of undefined (reading 'reduce')"
[ERROR][2023-11-14 10:18:12] ...lsp/handlers.lua:535	"Failed to reindex: Cannot read properties of undefined (reading 'reduce')"

I don't really know what this means. At least it seems we are a few steps further.

I have the same problem myself, I also get Undefined step everywhere

@M4urici0GM
Copy link

Using the branch npm i -g @binhtran432k/cucumber-language-server@1.4.0 i was able to configure my lsp with config:

{
    cmd = { "~/.nvm/versions/node/v16.20.2/bin/cucumber-language-server", "--stdio" },
    settings = {
        cucumber = {
            cucumber = {
                features = { "**/*.feature" },
                glue = { "**/*Step*.java" },
            }
        }
    },
    on_attach = function(client, bufnr)
        print("attached to cucumber file")
        vim.keymap.set('n', "gd", vim.lsp.buf.definition, { buffer = 0 })
        vim.keymap.set('n', "gn", vim.diagnostic.goto_next, { buffer = 0 })
        vim.keymap.set('n', "gb", vim.diagnostic.goto_prev, { buffer = 0 })
    end
}

@binhtddev binhtddev force-pushed the fix/standalone-startup branch from e6c05cd to 514f3da Compare January 7, 2024 08:08
@binhtddev binhtddev changed the title Fix standalone script startup fix(startup): fix start standalone outside vscode Jan 7, 2024
@binhtddev binhtddev self-assigned this Jan 7, 2024
@kieran-ryan kieran-ryan added the πŸ› bug Defect / Bug label Jan 7, 2024
Copy link
Member

@kieran-ryan kieran-ryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Firstly, thanks @binhtran432k for making an excellent contribution to the project - and welcome to our Slack community also; secondly thanks all for your patience on this - a review has been pending for a considerable time.

I'd like to support to get this reviewed and merged. However, I'm unfamiliar with Neovim - so you might have to bear with me while I get to grips with spinning up the Language Server with it, hopefully end of next week.

To close this out, some items we may need to achieve are as follows:

  • Tested in VSCode - see contributing guidelines
  • Tested on Windows - particularly the file path change
  • Consider whether unit tests can be written covering the file path change - ideally tests that fail with the previous state and pass with the changed state
  • Ensure changing from file:/// to a path would not have any impact if we were to enable the language server to work in browser-based contexts in future
  • Consider whether we should include a lightweight Usage or Installation section in the README with a subsection for using Neovim - explaining how to complete installation - perhaps this is an area you could assist @harleyreevesmartin - as a newer user looking to contribute and as I observe you are a Neovim user

@kumpan-david
Copy link

I managed to get it working with a little hacking using nvim v0.9.1 on macOS Sonoma 14.2.1.
Although I only tested with @cucumber/language-server@1.2.0 since that's the version the Mason Registry provides.

Since tree-sitter currently crashes on node > 19 I reinstalled the dependencies using node v16.17.0 and patched the bin-script to use the node-server instead of the wasm-server.

So if anyone using nvim, lspconfig and Mason comes, here this is a temporary workaround.

//cucumber-language-server/node_modules/.bin/cucumber-language-server
#!/change/this/path/to/v16.17.0/bin/node
/* eslint-disable @typescript-eslint/no-var-requires */
require('source-map-support').install()
const url = require('url')
const { startNodeServer, NodeFiles } = require('@cucumber/language-server/node')
const wasmBaseUrl = url.pathToFileURL(
  `file:///${__dirname}/../node_modules/@cucumber/language-service/dist`
)

startNodeServer(wasmBaseUrl.href, (rootUri) => new NodeFiles(rootUri))

Another detail I had to add was to double up the lspconfig settings and pass empty parameterTypes to prevent some errors from @cucumber/language-service

require("lspconfig").cucumber_language_server.setup({
  settings = {
    cucumber = {
      features = { "**/*.feature" },
      glue = { "**/*.steps.ts" },
      parameterTypes = {},
    },
    features = { "**/*.feature" },
    glue = { "**/*.steps.ts" },
    parameterTypes = {},
  },
})

@binhtddev binhtddev force-pushed the fix/standalone-startup branch from 96bf033 to 9733fec Compare January 31, 2024 05:31
@binhtddev
Copy link
Member Author

I managed to get it working with a little hacking using nvim v0.9.1 on macOS Sonoma 14.2.1. Although I only tested with @cucumber/language-server@1.2.0 since that's the version the Mason Registry provides.

Since tree-sitter currently crashes on node > 19 I reinstalled the dependencies using node v16.17.0 and patched the bin-script to use the node-server instead of the wasm-server.

So if anyone using nvim, lspconfig and Mason comes, here this is a temporary workaround.

//cucumber-language-server/node_modules/.bin/cucumber-language-server
#!/change/this/path/to/v16.17.0/bin/node
/* eslint-disable @typescript-eslint/no-var-requires */
require('source-map-support').install()
const url = require('url')
const { startNodeServer, NodeFiles } = require('@cucumber/language-server/node')
const wasmBaseUrl = url.pathToFileURL(
  `file:///${__dirname}/../node_modules/@cucumber/language-service/dist`
)

startNodeServer(wasmBaseUrl.href, (rootUri) => new NodeFiles(rootUri))

Another detail I had to add was to double up the lspconfig settings and pass empty parameterTypes to prevent some errors from @cucumber/language-service

require("lspconfig").cucumber_language_server.setup({
  settings = {
    cucumber = {
      features = { "**/*.feature" },
      glue = { "**/*.steps.ts" },
      parameterTypes = {},
    },
    features = { "**/*.feature" },
    glue = { "**/*.steps.ts" },
    parameterTypes = {},
  },
})

Hi @kumpan-david, thank you again for your help. Unfortunately, a significant refactor implemented after v1.2.0 makes reverting to that version impractical. However, I'm glad to report that this fix works with the latest version. I appreciate your understanding.

@binhtddev
Copy link
Member Author

Hi @kieran-ryan,

I've pushed new commits that accomplish the following:

Testing:

  • Completed testing in VSCode.
  • Conducted testing on Windows.

Unit Testing:

  • Added a unit test that starts the actual language server and verifies the absence of errors.
  • Noted a minor error (out of scope for this fix) with a TODO in the test file.

External VSCode Usage:

  • Added a note for users working outside of VSCode.

Please review the changes and let me know if you have any questions or feedback.

@FuzzyAzurik
Copy link

FuzzyAzurik commented Feb 9, 2024

@binhtran432k from a fellow neovim user, thank you so much!
I was able to get a working cucumber-language-server by installing your branch!
I am using node 18.19.0 and neovim 0.9.5

This issue has been bugging me for months!

@helgardferreira
Copy link

Any chance this can get merged anytime soon?

@binhtddev binhtddev linked an issue Mar 3, 2024 that may be closed by this pull request
Copy link
Member

@kieran-ryan kieran-ryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work @binhtran432k - appreciate the changes. Just two small comments to clarify the README documentation and to reuse some test code, and then we can merge and go for release. Well done! πŸ‘

Also if could confirm unit tests are executing with node v18 - I had some issues but might be local.

test(standalone): test startup success
docs: add external vscode usage session
@binhtddev binhtddev force-pushed the fix/standalone-startup branch from 9733fec to 7cda2e9 Compare March 26, 2024 05:12
@binhtddev binhtddev requested a review from kieran-ryan March 26, 2024 05:12
@binhtddev
Copy link
Member Author

@kieran-ryan, Thank you for your review. I have just completed the requested changes.

@kieran-ryan kieran-ryan merged commit 1875fb8 into cucumber:main Mar 26, 2024
@helgardferreira
Copy link

Thanks everyone πŸ™ this is a life saver

@kieran-ryan
Copy link
Member

v1.5.0 is now available πŸš€

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

πŸ› bug Defect / Bug

Projects

None yet

10 participants