typescript-tools.nvim icon indicating copy to clipboard operation
typescript-tools.nvim copied to clipboard

Disabling auto imports on completion

Open vanaigr opened this issue 1 year ago • 1 comments

Currently there seems to be no option to exclude module exports from completion list, or stop the plugin from automatically adding missing imports on such completion.

E.g. for the project below, completing value in file2.js would automatically add value to the import statement on line 1, which may be unwanted.

file1.js
var value = 5
var otherValue = 6

export default value
export { otherValue }
file2.js
import * as values from './file1.js'
package.json
{
    "name": "test",
    "type": "module",
    "version": "1.0.0",
    "main": "file2.js",
}

image image

TypeScript server exposes an option to disable module exports, but providing it in tsserver_file_preferences in the plugin config doesn't work.

require("typescript-tools").setup {
  settings = {
    ...
    tsserver_file_preferences = {
      includeCompletionsForModuleExports = false,
      includeExternalModuleExports = false
    }
  }
}

The reason this has no effect on completions is that the plugin overrides these options when requesting completion information:

https://github.com/pmizio/typescript-tools.nvim/blob/f8c2e0b36b651c85f52ad5c5373ff8b07adc15a7/lua/typescript-tools/protocol/text_document/completion/init.lua#L58-L69

vanaigr avatar Sep 10 '24 04:09 vanaigr

Note: the autoimport on completion is done here:

https://github.com/pmizio/typescript-tools.nvim/blob/f8c2e0b36b651c85f52ad5c5373ff8b07adc15a7/lua/typescript-tools/protocol/text_document/completion/resolve.lua#L171

commenting this line still shows the completion item but disables file changes.

vanaigr avatar Sep 10 '24 04:09 vanaigr