Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabling auto imports on completion #296

Open
vanaigr opened this issue Sep 10, 2024 · 1 comment
Open

Disabling auto imports on completion #296

vanaigr opened this issue Sep 10, 2024 · 1 comment

Comments

@vanaigr
Copy link

vanaigr commented Sep 10, 2024

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:

request {
command = c.CommandTypes.CompletionInfo,
arguments = vim.tbl_extend("force", {
file = vim.uri_to_fname(text_document.uri),
triggerKind = context.triggerKind,
triggerCharacter = vim.tbl_contains(c.CompletionsTriggerCharacter, trigger_character)
and trigger_character
or nil,
includeExternalModuleExports = true,
includeInsertTextCompletions = true,
}, utils.convert_lsp_position_to_tsserver(params.position)),
}

@vanaigr
Copy link
Author

vanaigr commented Sep 10, 2024

Note: the autoimport on completion is done here:

additionalTextEdits = make_text_edits(details.codeActions),

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant