dmmulroy / tsc.nvim

A Neovim plugin for seamless, asynchronous project-wide TypeScript type-checking using the TypeScript compiler (tsc)
MIT License
395 stars 21 forks source link

tsconfig.base.json #30

Closed camerow closed 1 year ago

camerow commented 1 year ago

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!!!

camerow commented 1 year ago

I've tried a quick configuration change to see if I could get this to work, however it doesn't seem to find project level diagnostic information, though it does seem to find the correct file:

-- bootstrap lazy.nvim, LazyVim and your plugins
require("config.lazy")
require("tsc").setup({
    flags = {
        build = true,
        project = function()
            local tsconfig = vim.fn.findfile("tsconfig.json", ".;")
            local nxTsBaseConfig = vim.fn.findfile("tsconfig.base.json", ".;")

            print("tsconfig", tsconfig)
            print("nxTsBaseConfig", nxTsBaseConfig)

            if nxTsBaseConfig ~= "" then
                return nxTsBaseConfig
            end

            if tsconfig ~= "" then
                return tsconfig
            end

            return nil
        end,
    },
}

As you can see, I'm using lazy.nvim - perhaps there is a conflict there somewhere?

dmmulroy commented 1 year ago

I'll take a look at this in the morning - any chance you could throw together a small nx repo that I can for sure reproduce this with?

I have one suspicion that the problem may be that I'm using vim.tbl_extend instead of vim.tbl_deep_extend here: https://github.com/dmmulroy/tsc.nvim/blob/main/lua/tsc/init.lua#L165

I'll also test that out in the morning and let you know what I come up with.

Sorry you're running into issues, but I appreciate the issue report ๐Ÿ™

dmmulroy commented 1 year ago

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!!!

Well then we'll definitely get it working for you ๐Ÿš€

dmmulroy commented 1 year ago

Well I tried the tbl_deep_extend option and didn't see much of a change - I cut a new release with the change anyways that you can try by upgrading (change here: https://github.com/dmmulroy/tsc.nvim/releases/tag/v1.8.0)

If you run tsc manually from the root of your repo does it typecheck correctly?

I probably will need more info on your tsconfig and repo setup.

dmmulroy commented 1 year ago

@camerow could you also try this configuration:

require("tsc").setup({
    flags = {
        noEmit = false,
        build = true,
        project = false,
    },
})
camerow commented 1 year ago

Hey @dmmulroy, thank you so much for looking into this so quickly. I'm learning that the neovim community is rad!

I've tried both of those configurations however no luck with either. I'll take some time to setup a small repo that reproduces the issue, though it may take me a bit. My personal machine died recently and I don't want to push personal stuff from my work machine.

Once I get a new laptop I'll create a small repro.

If you get a wild hair and want to try it on your end before I get that computer you could basically do this, and create some kind of bad import/export and it does successfully repro the issue. Eg in apps/nx-nvim create a BadExport.tsx and import that into App.tsx - something like that.

npx create-nx-workspace@latest                                                                                                   
Need to install the following packages:
  create-nx-workspace@latest
Ok to proceed? (y)

 >  NX   Let's create a new workspace [https://nx.dev/getting-started/intro]

โœ” Where would you like to create your workspace? ยท nx-nvim
โœ” Which stack do you want to use? ยท react
โœ” What framework would you like to use? ยท expo
โœ” Application name ยท nx-nvim
โœ” Enable distributed caching to make your CI faster ยท Yes

 >  NX   Creating your v16.8.1 workspace.

   To make sure the command works reliably in all environments, and that the preset is applied correctly,
   Nx will run "npm install" several times. Please wait.

โœ” Installing dependencies with npm
โœ” Successfully created the workspace: nx-nvim.
โœ” NxCloud has been set up successfully

That will run nx locally and create a small repo that uses their default configs.

If you're seeing what I'm seeing running :TSC won't return any errors, but if you open a buffer

dmmulroy commented 1 year ago

Going to look into this after work today

dmmulroy commented 1 year ago

@camerow I was able to reproduce your issue with the instructions you provided.

I was also able to get the plugin working - here is the configuration I used:

require("tsc").setup({
    flags = {
        project = "tsconfig.base.json",
        jsx = "react",
    },
})
camerow commented 1 year ago

๐Ÿพ That does seem to get project level errors working! Something else is wrong - likely a very specific thing in my work environment - which gives me tens of thousands of unresolved errors. Looks like package resolution or something, though I don't think it's something wrong on this plugin's end.

Thank you so much for your help and responses man! Truly appreciated ๐Ÿ™‡

Hopefully this little convo comes in handy for some other folks as well!

dmmulroy commented 1 year ago

Awesome - lmk if you have any more issues, happy to help!