Giter Site home page Giter Site logo

Comments (18)

GitMurf avatar GitMurf commented on June 14, 2024 1

@GitMurf thanks for the details! Pnpm and workspaces have been a thorn in my side for this plugin haha. Is there any chance you could create a small repo where the bug is reproducible?

Yes but may take me a week or so. Swamped right now as I'm sure you understand ;)

Again, awesome work on this plugin! Absolute game changer for me for typescript development :)

from tsc.nvim.

dmmulroy avatar dmmulroy commented on June 14, 2024

Can you share your tsconfig(s) and the project structure? In the mean time you can try setting the bin_path configuration option.

from tsc.nvim.

Armadillidiid avatar Armadillidiid commented on June 14, 2024

It's a company repository, so unfortunately, I am unable to provide detailed information about the project structure. However, I can tell you that the tsconfig file is generally the default configuration generated by Vite when initializing a new project.

Regarding your question about setting the bin_path configuration, could you please provide more context or specify how I could do that?

from tsc.nvim.

dmmulroy avatar dmmulroy commented on June 14, 2024

There is a bin_path config option that you can set to the path to your tsc binary. See #26 for more details.

from tsc.nvim.

Armadillidiid avatar Armadillidiid commented on June 14, 2024

I get the following error with the default configuration in the docs. Do I have to manually implement the utils function?

Error notify.error lazy.nvim Failed to run config for tsc.nvim

/home/xxx/.config/LazyVim/lua/plugins/tsc-nvim.lua:7: attempt to index global 'utils' (a nil value)

Config:

return {
  "dmmulroy/tsc.nvim",
  config = function()
    require("tsc").setup({
      auto_open_qflist = true,
      auto_close_qflist = false,
      bin_path = utils.find_tsc_bin(),
      enable_progress_notifications = true,
      flags = {
        noEmit = true,
        project = function()
          return utils.find_nearest_tsconfig()
        end,
      },
      hide_progress_notifications_from_history = true,
      spinner = { "", "", "", "", "", "", "", "" },
    })
  end,
}

I also tried manually adding the bin path to my global installed tsc, but it couldn't still find it.

lrwxrwxrwx 1 name wheel 38 Jul 9 17:56 tsc -> ../lib/node_modules/typescript/bin/tsc

Second confg:

return {
  "dmmulroy/tsc.nvim",
  config = function()
    require("tsc").setup({
      auto_open_qflist = true,
      auto_close_qflist = false,
      bin_path = "/lib/node_modules/typescript/bin/tsc",
      enable_progress_notifications = true,
      flags = {
        noEmit = true,
        project = function()
          return utils.find_nearest_tsconfig()
        end,
      },
      hide_progress_notifications_from_history = true,
      spinner = { "", "", "", "", "", "", "", "" },
    })
  end,
}

from tsc.nvim.

dmmulroy avatar dmmulroy commented on June 14, 2024

Could you try this

return {
  "dmmulroy/tsc.nvim",
  config = function()
    require("tsc").setup({
      bin_path = "/lib/node_modules/typescript/bin/tsc",
    })
  end,
}

To use utils you'll need to require it like let tsc_utils = require('tsc.utils'), however I would expect the configuration I posted above to work.

By default bin_path is set for you at runtime using utils.find_tsc_bin() which work like this:

M.find_tsc_bin = function()
  local node_modules_tsc_binary = vim.fn.findfile("node_modules/.bin/tsc", ".;")

  if node_modules_tsc_binary ~= "" then
    return node_modules_tsc_binary
  end

  return "tsc"
end

It essentially recursively searches upwards from the current buffers directory for node_modules/.bin/tsc until it hits your project root. If it's unsuccessful it defaults to just tsc which would be a global installation of tsc.

Then when you run the plugin this code executes:

  local tsc = config.bin_path

  if not utils.is_executable(tsc) then
    vim.notify(
      format_notification_msg(
        "tsc was not available or found in your node_modules or $PATH. Please run install and try again."
      ),
      vim.log.levels.ERROR,
      get_notify_options()
    )

    return
  end

I'm assuming that invoking which tsc yields /lib/node_modules/typescript/bin/tsc?

from tsc.nvim.

dmmulroy avatar dmmulroy commented on June 14, 2024

I also just installed a fresh project using npm create vite@latest my-vite-app -- --template vanilla-typescript and everything worked using the default config (require("tsc").setup()), so you may need to add some logging to the plugin or call utils.find_tsc_bin() from the status line cmdline (e.g. :lua print(vim.inspect(require('tsc.utils').find_tsc_bin())))

from tsc.nvim.

Armadillidiid avatar Armadillidiid commented on June 14, 2024

No, invoking which tsc returns ~/.local/bin/tsc, which is a symlink to /lib/node_modules/typescript/bin/tsc . Therefore, I opted to use that instead. In any case, I managed to get it working by utilizing the utility function you provided. I had ChatGPT to make any corrections if needed and it worked. Specifying the bin_path never worked, nor did requiring the tsc.utils.

Here's the working configuration:

local utils = {}

utils.find_tsc_bin = function()
  local node_modules_tsc_binary = vim.fn.findfile("node_modules/.bin/tsc", ".;")

  if node_modules_tsc_binary ~= "" then
    return node_modules_tsc_binary
  end

  return "tsc"
end

return {
  "dmmulroy/tsc.nvim",
  config = function()
    require("tsc").setup({
      bin_path = utils.find_tsc_bin(),
    })
  end
}

from tsc.nvim.

dmmulroy avatar dmmulroy commented on June 14, 2024

That's really bizarre. You should at least be able to simplify that to just:

return {
  "dmmulroy/tsc.nvim",
  config = function()
    require("tsc").setup({
      bin_path = require('tsc.utils').find_tsc_bin(),
    })
  end
}

I wonder if vim.fn.executable12 is doing something unexpected

executable({expr}) executable()
This function checks if an executable with the name {expr}
exists. {expr} must be the name of the program without any
arguments.
executable() uses the value of $PATH and/or the normal
searchpath for programs. PATHEXT
On MS-Windows the ".exe", ".bat", etc. can optionally be
included. Then the extensions in $PATHEXT are tried. Thus if
"foo.exe" does not exist, "foo.exe.bat" can be found. If
$PATHEXT is not set then ".exe;.com;.bat;.cmd" is used. A dot
by itself can be used in $PATHEXT to try using the name
without an extension. When 'shell' looks like a Unix shell,
then the name is also tried without adding an extension.
On MS-Windows it only checks if the file exists and is not a
directory, not if it's really executable.
On Windows an executable in the same directory as Vim is
always found (it is added to $PATH at |startup|).
The result is a Number:
1 exists
0 does not exist
-1 not implemented on this system
|exepath()| can be used to get the full path of an executable.

Footnotes

from tsc.nvim.

evanrichards avatar evanrichards commented on June 14, 2024

I was also hitting this issue. For whatever reason running :echo vim.fn.findfile("node_modules/.bin/tsc", ".;") gave me nothing, but running :echo vim.fn.findfile("node_modules/.bin/tsc") spit out the correct tsc path. I updated my config setup to look like this:

require("tsc").setup({
	auto_open_qflist = true,
	auto_close_qflist = false,
	bin_path = vim.fn.findfile("node_modules/.bin/tsc"),
	enable_progress_notifications = true,
	flags = {
		noEmit = true,
		project = function()
			return vim.fn.findfile("tsconfig.json")
		end,
	},
	hide_progress_notifications_from_history = true,
	spinner = { "", "", "", "", "", "", "", "" },
})

note that i hit the same issue in the project file flag config.

from tsc.nvim.

dmmulroy avatar dmmulroy commented on June 14, 2024

@evanrichards do you think you could replicate the issue in a small repo and post it?

from tsc.nvim.

sami616 avatar sami616 commented on June 14, 2024

Very strange this also seems to be an issue here, im working in a pnpm monorepo with build = true set.

from tsc.nvim.

dmmulroy avatar dmmulroy commented on June 14, 2024

@sami616 Could you create a small pnpm monorepo where this is reproducible? I've never used pnpm or it's monorepo capabilities before.

did overiding the settings as @evanrichards work?

from tsc.nvim.

dmmulroy avatar dmmulroy commented on June 14, 2024

@sami616 could you try using this config

require("tsc").setup({
	flags = {
		noEmit = false,
		build = true,
		project = false,
	},
})

from tsc.nvim.

dmmulroy avatar dmmulroy commented on June 14, 2024

Closing this as stale - please let me know if you or anyone encounters this

from tsc.nvim.

GitMurf avatar GitMurf commented on June 14, 2024

@dmmulroy fyi I just started using your awesome plugin and I ran into similar issues. I also use pnpm as someone above mentioned but I don't think that should be a problem. I think potentially the problem is due to windows and likely path issues (backslashes vs forward, escaping, spaces in paths etc.). This is the most common issue I have ran into with many plugins in the neovim community. Curious if you have had a chance to test on windows?

That all being said, my solution was that I could use the defaults as provided in the readme except I had to change it to use bin_path = "tsc". All is working nicely after making this change.

from tsc.nvim.

dmmulroy avatar dmmulroy commented on June 14, 2024

@GitMurf thanks for the details! Pnpm and workspaces have been a thorn in my side for this plugin haha. Is there any chance you could create a small repo where the bug is reproducible?

from tsc.nvim.

Related Issues (20)

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.