cucumber / language-server

Cucumber Language Server
MIT License
33 stars 19 forks source link

fix(startup): fix start standalone outside vscode #74

Closed binhtran432k closed 4 months ago

binhtran432k commented 1 year ago

🤔 What's changed?

⚡️ What's your motivation?

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

🏷️ What kind of change is this?

♻️ 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:


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

pprotas commented 1 year ago

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 commented 1 year ago

This also fixes #79

speelbarrow commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

@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 commented 9 months ago

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 - :white_check_mark:
  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 commented 8 months ago

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 commented 8 months ago

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
}
kumpan-david commented 6 months ago

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 = {},
  },
})
binhtran432k commented 6 months ago

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.

binhtran432k commented 6 months ago

Hi @kieran-ryan,

I've pushed new commits that accomplish the following:

Testing:

Unit Testing:

External VSCode Usage:

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

FuzzyAzurik commented 6 months ago

@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 commented 5 months ago

Any chance this can get merged anytime soon?

binhtran432k commented 4 months ago

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

helgardferreira commented 4 months ago

Thanks everyone 🙏 this is a life saver

kieran-ryan commented 4 months ago

v1.5.0 is now available 🚀