allegro / typescript-strict-plugin

Typescript plugin that allows turning on strict mode in specific files or directories.
MIT License
338 stars 29 forks source link

How to use with an LSP host other than vscode? #55

Open beaugunderson opened 1 year ago

beaugunderson commented 1 year ago

Hi there, I'm using neovim with the typescript-language-server language server. How can I see my strict violations using this language server?

I use mason to manage my LSP configs, so the version installed gets installed by mason as:

/Users/beau/.local/share/nvim/mason/packages/typescript-language-server/node_modules/typescript/lib/tsserver.js

Anyone had luck getting this working in vim?

KostkaBrukowa commented 1 year ago

Hey I'm using nvim with typescript-language-server and mason and it works for me. If you've followed every step from readme it should work out of the box.

beaugunderson commented 1 year ago

the only thing I've done differently is added a non-existent path as the paths array and used the @ts-strict comment instead so that my project is opt-in instead of opt-out... it works for tsc-strict but I get nothing in vim sadly

KostkaBrukowa commented 1 year ago

Could you share you vim config?

beaugunderson commented 1 year ago

@KostkaBrukowa sure! here you go: https://gist.github.com/beaugunderson/7acffd22a8df616cba263655aaa6b6fe

and alternately, since yours is working, if you share yours I can see how it differs from my own :)

61091

12774

kaiwah commented 10 months ago

Just fyi, I ran across this issue and took many hours of debugging but I realized it was due to a pathing issue for me.

Basically I had a few tsconfig.json scattered throughout my proj directory, that extends the main one in root. But because the root directory for mason tsserver resolves to the nearest tsconfig... it ended up with the wrong root dir which mean't all the relative paths included in the plugin technically were incorrect.

i.e.

// main tsconfig.json in root
{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-strict-plugin",
        "paths": [
          "foo/bar/baz",
        ]
     }
   ]
 }
// tsconfig.json in foo/bar
{
  extends: "../../tsconfig.json"
}

Above setup causes:

tsserver root dir = root/foo/bar and now the plugin path instead of being ./foo/bar/baz which I expected, ended up being root/foo/bar/foo/bar/baz which does not exist.

Thus the following worked for me:

YMMV however