dmmulroy / tsc.nvim Goto Github PK
View Code? Open in Web Editor NEWA Neovim plugin for seamless, asynchronous project-wide TypeScript type-checking using the TypeScript compiler (tsc)
License: MIT License
A Neovim plugin for seamless, asynchronous project-wide TypeScript type-checking using the TypeScript compiler (tsc)
License: MIT License
I get this error in my typescript vite project. It was working before for a long time until after I updated yesterday. Here is my package.json:
"packages": {
"": {
"dependencies": {
"@headlessui/react": "^1.7.14",
"@heroicons/react": "^2.0.17",
"@tailwindcss/forms": "^0.5.3",
"@tanstack/react-query": "^4.29.13",
"@tanstack/react-query-devtools": "^4.29.14",
"@tanstack/react-table": "^8.9.1",
"@types/crypto-js": "^4.1.1",
"@types/react-csv": "^1.1.3",
"axios": "^1.4.0",
"class-variance-authority": "^0.6.0",
"clsx": "^1.2.1",
"color": "^4.2.3",
"crypto-js": "^4.1.1",
"date-fns": "^2.30.0",
"framer-motion": "^10.12.16",
"jwt-decode": "^3.1.2",
"react": "^18.2.0",
"react-csv": "^2.2.2",
"react-day-picker": "^8.7.1",
"react-dom": "^18.2.0",
"react-hook-form": "^7.43.9",
"react-icons": "^4.8.0",
"react-router-dom": "^6.11.2",
"react-toastify": "^9.1.3",
"recharts": "^2.5.0",
"tailwind-merge": "^1.12.0",
"vite-plugin-svgr": "^3.2.0",
"zod": "^3.21.4"
},
"devDependencies": {
"@faker-js/faker": "^8.0.0",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"@vitejs/plugin-react-swc": "^3.0.0",
"autoprefixer": "^10.4.14",
"eslint": "^8.38.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.3.4",
"postcss": "^8.4.23",
"prettier": "^2.8.8",
"prettier-plugin-tailwindcss": "^0.3.0",
"tailwindcss": "^3.3.2",
"typescript": "^5.0.2",
"vite": "^4.3.2"
}
}
Hello. Is it possible to have ability to use :make which is pretty common compilation option?
Hello and thank you for this interesting project - just one step closer to VSCode feature parity :D
I've tried the plugin and it does work great, but with one small issue - it seems that it sends multiple nvim-notify
notifications instead of updating the one.
I'm using a setup based on ecovim, so I don't think there's anything I've done which broke things. My setup is available at nvim-dotfiles.
I'm pretty new to Vim and don't know exactly how to debug this, although I do have a basic understanding of the pieces involved in the setup. I do see that updating notifications should be possible.
The notifications look like this:
Thanks again!
When I try to open the file on qflist I get sent to an empty buffer.
The type errors are captured as expected, but you can even see on the preview that the file is empty
If I press enter in any of the files, I get sent to an empty buffer:
Additional info:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": [
"./*"
]
},
"target": "es6",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
],
"exclude": [
"node_modules"
]
}
I just installed tsc.nvim, and tried to run it but it spamming nvim-notify errors. Even when the project has erros, nothing is being reported
Gravação de tela de 2023-05-02 20-01-57.webm
I have a monorepo where I use ts project references. I want to start the tsc from the nvim cwd (repo root dir), by executing "tsc --build /home/user/my-repo/tsconfig.json --watch".
I investigated the code, and I could not figure out a way to do this (specifically to define the path of tsconfig).
Project references build command cannot be invoked with --project.
I tried to trick it with bin_path option, but you check whether is executable.
Via the flags you prepend double-dash.
Maybe you can provide a way to directly specify the command instead of the various options-flags?
I think this may be the only way, because project references --build and rest args, should be placed in a specific order. (--build first, then tsconfig, then rest args).
Thanks!
Nice plugin btw :)
Hi,
would be awesome if project diagnostic was done by tsserver lsp. I found that tsserver
have geterrForProject
or geterr
which return diagnostics for file or project. I would also can make PR for.
At work we used nx
to generate our monorepo structure. We've got a tsconfig.base.json
in the root of our project. The search function in tsc.nvim
only looks for tsconfig.json
as far as I can tell.
Could you give me some guidance with how to configure the options in require('tsc").setup(...)
to find the correct root file?
I've confirmed that I get project level diagnostics if I rename the file tsconfig.base.json
-> tsconfig.json
, however I know the team wouldn't appreciate me renaming this simply so that I can use Neovim.
Thanks in advanced, and thanks for such a great tool!
On a personal note, I'm new to Neovim as of this week and really enjoying myself. If I can fix this issue I can make it my go to editor professionally at work!!!
Hi, thanks for this plugin, I've found it very useful.
I use Vue at work and privately as well and vue-tsc is the go-to typechecker, as it also parses the .vue files into typecheckable TypeScript. I would be grateful if you could also include the command name as an option (i.e. npx vue-tsc
in this case) to override the default behaviour, or an option to include the path to binary (I see that this would probably be the easiest option)? As far as I am aware the interface and console output are the same.
Hello, here's the text from the chat:
i have a monorepo with a tsconfig in
/api/tsconfig.json and then one in
/app/website/tsconfig.json
-- I see the build = true flag is supposed to hopefully seek these out,
but in the setup object, if i set flags.build = true, and open a ts file, it errors out that "project" is unset..
in the docs project is defined by
project = function()
return utils.find_nearest_tsconfig()
end, func
but i need to return two config files...
And here is a link to the monorepo:
Hello. I've found that with --incremental
flag tsc works faster cause it uses cache. Hot to add this flag to tsc.nvim
?
This works:
local function find_closest_file(match_strings, start_dir, depth)
-- Initialize depth if not provided
depth = depth or 0
-- Maximum depth to prevent infinite recursion
local max_depth = 10
-- Determine the starting directory: current buffer's directory or provided start_dir
start_dir = start_dir or vim.fn.expand('%:p:h') or vim.fn.getcwd()
-- Log the attempt and depth
-- Base case: if maximum depth is reached, stop the search
if depth > max_depth then
return nil
end
-- Iterate over the array of match strings and construct the find command
for _, match_string in ipairs(match_strings) do
local command = string.format("find '%s' -type f -name '*%s*' -maxdepth 1", start_dir, match_string)
local handle = io.popen(command)
local result = handle:read("*a")
handle:close()
-- Split the result into lines (files)
local files = {}
for line in result:gmatch("[^\r\n]+") do
table.insert(files, line)
end
-- If a file is found, return its path
if #files > 0 then
return files[1] -- Return the first matching file path
end
end
-- No file found, move to the parent directory and repeat the search
local parent_dir = vim.fn.fnamemodify(start_dir, ':h')
if parent_dir == start_dir then
-- If the parent directory is the same as the current directory, we're at the root
return nil
else
-- Recursive call to search in the parent directory, incrementing the depth
return find_closest_file(match_strings, parent_dir, depth + 1)
end
end
return find_closest_file
-----EXAMPLE USEAGE------
local find_closest_file = require("path-from-lua-root-to-the-file-where-you-saved-the-above-function")
local output = find_closest_file({'tsConfig.app.json', tsConfig.base.json'})
return output in your 'project' function
profit
Hi, Just wondering if supporting something like this would be possible. I am using Trouble for Diagnostics, quickfix etc.
Currently I am using an autocmd to hook into when the quickfix list is opened to swap to using trouble:
vim.api.nvim_create_augroup("trouble-quickfix", { clear = true })
vim.api.nvim_create_autocmd({ "BufWinEnter" }, {
group = "trouble-quickfix",
callback = function()
if vim.bo.buftype == "quickfix" then
print(#(vim.fn.getqflist()))
if #(vim.fn.getqflist()) > 0 then
vim.schedule(function()
vim.cmd("Trouble quickfix")
end)
vim.schedule(function()
vim.cmd("ccl")
end)
else
vim.schedule(function()
vim.cmd("TroubleClose")
end)
end
end
end,
})
However this does mean this behaviour isn't scoped to just tsc errors. Would it be possible to expose an on_qflist_open
callback to allow scoping this kind of behaviour?
Happy to make a PR if this would be of interest
Cheers
Thanks for making a great plugin! I've noticed that it seems to also analyze code in node_modules
. Is this intended behaviour? If yes, it would be awesome if there were an option to disable this 🙂
Installed the plugin and set it up with the following config:
require('tsc').setup({
auto_open_qflist = true,
flags = {
build = true,
},
})
I then ran TSC in a pnpm monorepo and no errors were found, even though running typecheck with tsc finds errors.
I tested the plugin in a non-monorepo project and it worked fine.
So, wondering if this is a missing feature or am I missing some config?
Thanks for the plugin
Hey there! Thanks for this plugin--could be a great enhancement for working with TypeScript in neovim!
Would it be possible to detect and use the current project's version of tsc before attempting to use a globally installed version?
I prefer to use project-local binaries for things like this wherever possible.
I was able to find a quick reference to how null-ls handles this for prettier, as an example:
Thanks for the update to use the local tsc
install! Works well. :)
I've noticed that if I run :TSC
, fix some changes, then run the :TSC
command again, the panel doesn't update to show the reduced error list. I have to close the panel first, and then run :TSC
.
Some of the TypeScript projects that I'm working with are using project references and some not. That means in some repositories I have to compile with tsc --build
and in some not. As far as I understood the docs it is possible to enable --build
with this configuration
flags = {
build = true,
},
but then I have build
enabled for all other projects as well. How can I handle multiple projects with different configurations?
PS: the same for noEmit
. In some projects I want to have something emitted and in some not.
Hi, Just wondering if supporting something like this would be possible. I am using Trouble for Diagnostics, quickfix etc.
Currently I am using an autocmd to hook into when the quickfix list is opened to swap to using trouble:
vim.api.nvim_create_augroup("trouble-quickfix", { clear = true })
vim.api.nvim_create_autocmd({ "BufWinEnter" }, {
group = "trouble-quickfix",
callback = function()
if vim.bo.buftype == "quickfix" then
print(#(vim.fn.getqflist()))
if #(vim.fn.getqflist()) > 0 then
vim.schedule(function()
vim.cmd("Trouble quickfix")
end)
vim.schedule(function()
vim.cmd("ccl")
end)
else
vim.schedule(function()
vim.cmd("TroubleClose")
end)
end
end
end,
})
However this does mean this behaviour isn't scoped to just tsc errors. Would it be possible to expose an on_qflist_open
callback to allow scoping this kind of behaviour?
Happy to make a PR if this would be of interest
Cheers
Awesome work. Have you considered doing the same for prettier and eslint? Especially if their quickfix listings can be interleaved.
Hi,
this is a really nice plugin. Saved me a some time in my workflow. Thanks a lot for that.
Have you thought about adding a watch mode with a corresponding TSCWatch command? Do you see any problems with this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.