1

I am almost certain that I have a mistake in my Neovim configuration... The Neovim ~/.config/nvim directory I'm using is:

https://github.com/andrewgregorywright/nvim-config/tree/main

I've created an empty project with a single TypeScript file:

// src/index.ts

function add(a?: number, b: number, c: number) {
    var x = 42
    return b + c
}

console.log(add(undefined, 5, 2))

In the root of the project is a tsconfig.json file:

// tsconfig.json

{
  "compilerOptions": {
    "rootDir": "src",
    "outDir": "dist",
    "target": "es2022",
    "lib": [
      "es2022"
    ],
    "module": "nodenext",
    "esModuleInterop": true,
    "strict": true,
    "noImplicitAny": true,
    "noUnusedParameters": false,
    "noUnusedLocals": false,
    "removeComments": true
  },
  "include": ["*"],
  "exclude": ["node_modules/*"]
}

However, when I open src/index.ts, there's a warning from the LSP tsserver on the line that contains the function signature for add which reads:

'a' is declared but its value is never read.

A similar warning occurs on the line below it for the variable x. The tsconfig.json file has noUnusedParameters and noUnusedLocals both set to false, but it seems like the LSP server is not using the settings. I'm not sure what to do.

In ~/.config/nvim/lua/plugins/nvim-cmp.lua the following line configures tsserver:

lspconfig.tsserver.setup{}

I attempted to find the log files for tsserver but wasn't sure where to look. It was installed globally with npm.

2
  • It seems to me that the LSP server don't consider the configuration file. Did you try to change the current directory to the root of the project? Is the project under git control? What if the ts file is next to the configuration file? Sep 28, 2023 at 4:59
  • 1
    @VivianDeSmedt tsserver should at least be aware of the tsconfig.json file, at least according to some docs for the nvim-lspconfig plugin. (1) Running git init in the root directory of the project, (2) cd src && nvim index.ts, and/or (3) moving index.ts to the root directory of the project did not alleviate the diagnostic warnings, unfortunately.
    – Andrew
    Sep 28, 2023 at 7:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.