Skip to content

Make node executable configurable#237

Open
aromeronavia wants to merge 1 commit intopmizio:masterfrom
aromeronavia:improvement/allow-tsserver-node-executable-to-be-configurable
Open

Make node executable configurable#237
aromeronavia wants to merge 1 commit intopmizio:masterfrom
aromeronavia:improvement/allow-tsserver-node-executable-to-be-configurable

Conversation

@aromeronavia
Copy link

@aromeronavia aromeronavia commented Feb 16, 2024

Solves #237

Things done in this PR

  • Make node executable configurable so tsserver can run with any runtime (node, bun, deno, etc)

How I tested the project

  1. Pushed these commits to my github main branch
  2. Installed typescript tools pointing to my github
  use {
    "aromeronavia/typescript-tools.nvim",
    requires = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" },
  }
  1. Ran application with no configuration (defaulting to node)
  2. Ran application with bun configured

My demo videos are more than 10MB so I can't upload them (even tho I'm recording them at speed of light). Will try a different tool tomorrow I guess


function Process:start()
local command = is_win and "cmd.exe" or "node"
local command = is_win and "cmd.exe" or plugin_config.tsserver_node_executable
Copy link
Author

Choose a reason for hiding this comment

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

Moved default value to config.

aromeronavia added a commit to aromeronavia/typescript-tools.nvim that referenced this pull request Feb 16, 2024
Fix type definition in comments

Modify readme
@aromeronavia aromeronavia force-pushed the improvement/allow-tsserver-node-executable-to-be-configurable branch from 4754d83 to 2aa93d6 Compare February 16, 2024 05:50
Fix type definition in comments

Modify readme
@aromeronavia aromeronavia force-pushed the improvement/allow-tsserver-node-executable-to-be-configurable branch from 2aa93d6 to 1ac2ceb Compare February 16, 2024 05:51
@pmizio
Copy link
Owner

pmizio commented Feb 24, 2024

Hi, thanks for your contribution. I'm still on my vacation so I'll test it next week!

@aromeronavia
Copy link
Author

Enjoy your vacations!! I'm going to Cancun next week hehe will get some time to refresh too 🙏

Copy link
Collaborator

@KostkaBrukowa KostkaBrukowa left a comment

Choose a reason for hiding this comment

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

Have you tested it on windows with bun? I see that we add node argument when nvim is running on windows here

table.insert(self.args, 2, "node")

@qwexvf
Copy link

qwexvf commented Sep 30, 2024

bump any status on this pr?

@thodnev
Copy link

thodnev commented Oct 14, 2024

Hope it solves the problem addressed by @KostkaBrukowa in #237 (review)

I could make a PR if you like. Or the patch may be simply applied on top of aromeronavia/typescript-tools.nvim@1ac2ceb (kindly pinging @aromeronavia for that)

node-executable.patch

diff --git a/README.md b/README.md
index e31d001..7493550 100644
--- a/README.md
+++ b/README.md
@@ -144,6 +144,8 @@ require("typescript-tools").setup {
     -- locale of all tsserver messages, supported locales you can find here:
     -- https://github.com/microsoft/TypeScript/blob/3c221fc086be52b19801f6e8d82596d04607ede6/src/compiler/utilitiesPublic.ts#L620
     tsserver_locale = "en",
+    -- Node executable configuration (for example, bun)
+    tsserver_node_executable = "bun",
     -- mirror of VSCode's `typescript.suggest.completeFunctionCalls`
     complete_function_calls = false,
     include_completions_with_insert_text = true,
diff --git a/lua/typescript-tools/config.lua b/lua/typescript-tools/config.lua
index 2825b1d..e30d3d7 100644
--- a/lua/typescript-tools/config.lua
+++ b/lua/typescript-tools/config.lua
@@ -9,6 +9,7 @@
 ---@field tsserver_file_preferences table|fun(filetype: string): table
 ---@field tsserver_max_memory number|"auto"
 ---@field tsserver_locale string
+---@field tsserver_node_executable string
 ---@field complete_function_calls boolean
 ---@field expose_as_code_action ("fix_all"| "add_missing_imports"| "remove_unused" | "remove_unused_imports")[]
 ---@field include_completions_with_insert_text boolean
@@ -125,6 +126,11 @@ function M.load_settings(settings)
       "string",
       true,
     },
+    ["settings.tsserver_node_executable"] = {
+      settings.tsserver_node_executable,
+      "string",
+      true,
+    },
     ["settings.complete_function_calls"] = { settings.complete_function_calls, "boolean", true },
     ["settings.expose_as_code_action"] = {
       settings.expose_as_code_action,
@@ -163,6 +169,10 @@ function M.load_settings(settings)
     __store.tsserver_file_preferences = {}
   end
 
+  if not settings.tsserver_node_executable then
+    __store.tsserver_node_executable = "node"
+  end
+
   if not M.tsserver_log_level[settings.tsserver_logs] then
     __store.tsserver_logs = M.tsserver_log_level.off
   end
diff --git a/lua/typescript-tools/process.lua b/lua/typescript-tools/process.lua
index a1dd48f..d10763d 100644
--- a/lua/typescript-tools/process.lua
+++ b/lua/typescript-tools/process.lua
@@ -123,7 +123,7 @@ local function parse_response(initial_chunk, on_response)
 end
 
 function Process:start()
-  local command = is_win and "cmd.exe" or "node"
+  local command = is_win and "cmd.exe" or plugin_config.tsserver_node_executable
 
   if type(plugin_config.tsserver_max_memory) == "number" then
     table.insert(self.args, 1, "--max-old-space-size=" .. plugin_config.tsserver_max_memory)
@@ -131,7 +131,7 @@ function Process:start()
 
   if is_win then
     table.insert(self.args, 1, "/c")
-    table.insert(self.args, 2, "node")
+    table.insert(self.args, 2, plugin_config.tsserver_node_executable)
   end
 
   local args = {

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants