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

Auto import stops working after switching to ESM modules #451

Open
GrantJamesPowell opened this issue Jan 26, 2024 · 1 comment
Open

Auto import stops working after switching to ESM modules #451

GrantJamesPowell opened this issue Jan 26, 2024 · 1 comment

Comments

@GrantJamesPowell
Copy link

Hey! thanks for the great work on this project. I think I'm just missing something dumb here. I switched my library to use esmodules and the auto import stopped working. I've attached a video of the auto import, and the logs of the tsserver that show that tsserver seems to correctly identify what I'm trying to import. Using the quick fix actions seems to work too! I can't see any reason why the auto import option would stop showing up after this change?

Before

auto.import.working.mov

After

(notice it doesn't auto import on tab, but the quick fix works fine??)
https://github.com/neoclide/coc-tsserver/assets/16196910/f41067c5-2174-4c62-8ac0-3ed532bf5c78

Change to .tsconfig.json

(I also changed all the imports to have the .js suffix to align with node16 module/module resolution

--- a/libs/nasty/tsconfig.json
+++ b/libs/nasty/tsconfig.json
@@ -1,6 +1,15 @@
 {
   "extends": "../../tsconfig.base.json",
-  "compilerOptions": {},
+  "compilerOptions": {
+    "module": "node16",
+    "moduleResolution": "Node16",
+    "target": "es2020",
+    "strict": true,
+    "verbatimModuleSyntax": false,
+    "declaration": true,
+    "sourceMap": true,
+    "declarationMap": true
+  },
   "rootDir": "../..",
   "files": [],
   "include": [],

TS server logs of After

Info 494  [10:48:37.795] request:
    {
      "seq": 16,
      "type": "request",
      "command": "completionInfo",
      "arguments": {
        "file": "/Users/grantpowell/src/cotera/libs/nasty/src/lib/builder/expression.spec.ts",
        "line": 10,
        "offset": 16,
        "includeExternalModuleExports": true,
        "includeInsertTextCompletions": true
      }
    }
Info 495  [10:48:37.796] Starting updateGraphWorker: Project: /Users/grantpowell/src/cotera/libs/nasty/tsconfig.spec.json
Info 496  [10:48:37.821] Finishing updateGraphWorker: Project: /Users/grantpowell/src/cotera/libs/nasty/tsconfig.spec.json Version: 5 structureChanged: false structureIsReused:: Completely Elapsed: 25.25770854949951ms
Info 497  [10:48:37.821] Different program with same set of files
Info 498  [10:48:37.822] getCompletionData: Get current token: 0.013458251953125
Info 499  [10:48:37.822] getCompletionData: Is inside comment: 0.03195762634277344
Info 500  [10:48:37.822] getCompletionData: Get previous token: 0.05604076385498047
Info 501  [10:48:37.822] getCompletionsAtPosition: isCompletionListBlocker: 0.05675029754638672
Info 502  [10:48:38.337] AutoImportProviderProject: attempted to add more than 10 dependencies. Aborting.
Info 503  [10:48:38.337] getExportInfoMap: cache miss or empty; calculating new results
Info 504  [10:48:38.857] AutoImportProviderProject: attempted to add more than 10 dependencies. Aborting.
Info 505  [10:48:38.857] getExportInfoMap: done in 1032.7750425338745 ms
Info 506  [10:48:39.356] AutoImportProviderProject: attempted to add more than 10 dependencies. Aborting.
Info 507  [10:48:39.373] collectAutoImports: resolved 26 module specifiers, plus 45 ambient and 96 from cache
Info 508  [10:48:39.373] collectAutoImports: response is complete
Info 509  [10:48:39.373] collectAutoImports: 16.204124450683594
Info 510  [10:48:39.373] getCompletionData: Semantic work: 1550.976375579834
Info 511  [10:48:39.391] getCompletionsAtPosition: getCompletionEntriesFromSymbols: 17.881999969482422
Perf 512  [10:48:39.392] 16::completionInfo: elapsed time (in milliseconds) 1597.2253
Info 513  [10:48:39.393] response:
    // ** I've removed the tons of options here, but it included `UnionAll` which I wanted! **
Info 514  [10:48:39.396] request:
    {
      "seq": 17,
      "type": "request",
      "command": "geterr",
      "arguments": {
        "delay": 0,
        "files": [
          "/Users/grantpowell/src/cotera/libs/nasty/src/lib/builder/expression.spec.ts"
        ]
      }
    }
Perf 515  [10:48:39.396] 17::geterr: async elapsed time (in milliseconds) 0.1855
Info 516  [10:48:39.397] event:
    {"seq":0,"type":"event","event":"syntaxDiag","body":{"file":"/Users/grantpowell/src/cotera/libs/nasty/src/lib/builder/expression.spec.ts","diagnostics":[]}}
Info 517  [10:48:39.495] event:
    {"seq":0,"type":"event","event":"requestCompleted","body":{"request_seq":17}}
Info 518  [10:48:39.495] request:
    {
      "seq": 18,
      "type": "request",
      "command": "completionEntryDetails",
      "arguments": {
        "file": "/Users/grantpowell/src/cotera/libs/nasty/src/lib/builder/expression.spec.ts",
        "line": 10,
        "offset": 16,
        "entryNames": [
          {
            "name": "UnionAll",
            "source": "./utilities.js",
            "data": {
              "exportName": "UnionAll",
              "exportMapKey": "8 9340 UnionAll ",
              "moduleSpecifier": "./utilities.js",
              "fileName": "/Users/grantpowell/src/cotera/libs/nasty/src/lib/builder/utilities.ts"
            }
          }
        ]
      }
    }
Info 519  [10:48:39.999] AutoImportProviderProject: attempted to add more than 10 dependencies. Aborting.
Info 520  [10:48:39.999] getExportInfoMap: cache hit
Info 521  [10:48:40.003] response:
    {"seq":0,"type":"response","command":"completionEntryDetails","request_seq":18,"success":true,"body":{"canceled":true}}
Info 522  [10:48:40.003] request:
    {
      "seq": 20,
      "type": "request",
      "command": "completionEntryDetails",
      "arguments": {
        "file": "/Users/grantpowell/src/cotera/libs/nasty/src/lib/builder/expression.spec.ts",
        "line": 10,
        "offset": 16,
        "entryNames": [
          {
            "name": "UnionAll",
            "source": "./utilities.js",
            "data": {
              "exportName": "UnionAll",
              "exportMapKey": "8 9340 UnionAll ",
              "moduleSpecifier": "./utilities.js",
              "fileName": "/Users/grantpowell/src/cotera/libs/nasty/src/lib/builder/utilities.ts"
            }
          }
        ]
      }
    }
Info 523  [10:48:40.503] AutoImportProviderProject: attempted to add more than 10 dependencies. Aborting.
Info 524  [10:48:40.503] getExportInfoMap: cache hit
Info 525  [10:48:40.506] response:
    {"seq":0,"type":"response","command":"completionEntryDetails","request_seq":20,"success":true,"body":{"canceled":true}}
Info 526  [10:48:40.507] request:
    {
      "seq": 22,
      "type": "request",
      "command": "completionEntryDetails",
      "arguments": {
        "file": "/Users/grantpowell/src/cotera/libs/nasty/src/lib/builder/expression.spec.ts",
        "line": 10,
        "offset": 16,
        "entryNames": [
          {
            "name": "UnionAll",
            "source": "./utilities.js",
            "data": {
              "exportName": "UnionAll",
              "exportMapKey": "8 9340 UnionAll ",
              "moduleSpecifier": "./utilities.js",
              "fileName": "/Users/grantpowell/src/cotera/libs/nasty/src/lib/builder/utilities.ts"
            }
          }
        ]
      }
    }
Info 527  [10:48:41.004] AutoImportProviderProject: attempted to add more than 10 dependencies. Aborting.
Info 528  [10:48:41.004] getExportInfoMap: cache hit
Info 529  [10:48:41.005] response:
    {"seq":0,"type":"response","command":"completionEntryDetails","request_seq":22,"success":true,"body":{"canceled":true}}
Info 530  [10:48:41.007] request:
    {
      "seq": 23,
      "type": "request",
      "command": "geterr",
      "arguments": {
        "delay": 0,
        "files": [
          "/Users/grantpowell/src/cotera/libs/nasty/src/lib/builder/expression.spec.ts"
        ]
      }
    }
Perf 531  [10:48:41.007] 23::geterr: async elapsed time (in milliseconds) 0.0990
Info 532  [10:48:41.008] event:
    {"seq":0,"type":"event","event":"syntaxDiag","body":{"file":"/Users/grantpowell/src/cotera/libs/nasty/src/lib/builder/expression.spec.ts","diagnostics":[]}}
Info 533  [10:48:41.101] event:
    {"seq":0,"type":"event","event":"requestCompleted","body":{"request_seq":23}}
Info 534  [10:48:41.102] request:
    {
      "seq": 24,
      "type": "request",
      "command": "completionEntryDetails",
      "arguments": {
        "file": "/Users/grantpowell/src/cotera/libs/nasty/src/lib/builder/expression.spec.ts",
        "line": 10,
        "offset": 16,
        "entryNames": [
          {
            "name": "UnionAll",
            "source": "./utilities.js",
            "data": {
              "exportName": "UnionAll",
              "exportMapKey": "8 9340 UnionAll ",
              "moduleSpecifier": "./utilities.js",
              "fileName": "/Users/grantpowell/src/cotera/libs/nasty/src/lib/builder/utilities.ts"
            }
          }
        ]
      }
    }
Info 535  [10:48:41.602] AutoImportProviderProject: attempted to add more than 10 dependencies. Aborting.
Info 536  [10:48:41.602] getExportInfoMap: cache hit
Info 537  [10:48:41.603] response:
    {"seq":0,"type":"response","command":"completionEntryDetails","request_seq":24,"success":true,"body":{"canceled":true}}
Info 538  [10:48:41.603] request:
    {
      "seq": 26,
      "type": "request",
      "command": "completionEntryDetails",
      "arguments": {
        "file": "/Users/grantpowell/src/cotera/libs/nasty/src/lib/builder/expression.spec.ts",
        "line": 10,
        "offset": 16,
        "entryNames": [
          {
            "name": "UnionAll",
            "source": "./utilities.js",
            "data": {
              "exportName": "UnionAll",
              "exportMapKey": "8 9340 UnionAll ",
              "moduleSpecifier": "./utilities.js",
              "fileName": "/Users/grantpowell/src/cotera/libs/nasty/src/lib/builder/utilities.ts"
            }
          }
        ]
      }
    }
Info 539  [10:48:42.104] AutoImportProviderProject: attempted to add more than 10 dependencies. Aborting.
Info 540  [10:48:42.104] getExportInfoMap: cache hit
Info 541  [10:48:42.106] response:
    {"seq":0,"type":"response","command":"completionEntryDetails","request_seq":26,"success":true,"body":{"canceled":true}}
Info 542  [10:48:42.106] request:
    {
      "seq": 27,
      "type": "request",
      "command": "geterr",
      "arguments": {
        "delay": 0,
        "files": [
          "/Users/grantpowell/src/cotera/libs/nasty/src/lib/builder/expression.spec.ts"
        ]
      }
    }
Perf 543  [10:48:42.107] 27::geterr: async elapsed time (in milliseconds) 0.0773
Info 544  [10:48:42.108] event:
    {"seq":0,"type":"event","event":"syntaxDiag","body":{"file":"/Users/grantpowell/src/cotera/libs/nasty/src/lib/builder/expression.spec.ts","diagnostics":[]}}
Info 545  [10:48:42.197] event:
    {"seq":0,"type":"event","event":"semanticDiag","body":{"file":"/Users/grantpowell/src/cotera/libs/nasty/src/lib/builder/expression.spec.ts","diagnostics":[{"start":{"line":10,"offset":15},"end":{"line":10,"offset":16},"text":"Cannot find name 'U'.","code":2304,"category":"error"}]}}
Info 546  [10:48:42.198] event:
    {"seq":0,"type":"event","event":"suggestionDiag","body":{"file":"/Users/grantpowell/src/cotera/libs/nasty/src/lib/builder/expression.spec.ts","diagnostics":[{"start":{"line":10,"offset":9},"end":{"line":10,"offset":12},"text":"'foo' is declared but its value is never read.","code":6133,"category":"suggestion","reportsUnnecessary":true}]}}
Info 547  [10:48:42.198] event:
    {"seq":0,"type":"event","event":"requestCompleted","body":{"request_seq":27}}
Info 548  [10:48:42.415] request:
    {
      "seq": 28,
      "type": "request",
      "command": "completionEntryDetails",
      "arguments": {
        "file": "/Users/grantpowell/src/cotera/libs/nasty/src/lib/builder/expression.spec.ts",
        "line": 10,
        "offset": 16,
        "entryNames": [
          {
            "name": "UnionAll",
            "source": "./utilities.js",
            "data": {
              "exportName": "UnionAll",
              "exportMapKey": "8 9340 UnionAll ",
              "moduleSpecifier": "./utilities.js",
              "fileName": "/Users/grantpowell/src/cotera/libs/nasty/src/lib/builder/utilities.ts"
            }
          }
        ]
      }
    }
Info 549  [10:48:42.951] AutoImportProviderProject: attempted to add more than 10 dependencies. Aborting.
Info 550  [10:48:42.951] getExportInfoMap: cache hit
Info 551  [10:48:42.952] response:
    {"seq":0,"type":"response","command":"completionEntryDetails","request_seq":28,"success":true,"body":{"canceled":true}}

@fannheyward
Copy link
Member

The completionEntryDetails request is sent to resolve additional information for a given completion item, from the trace logs, the tsserver didn't response auto-import codeAction to use.

Can you try this in VSCode to check it work or not?

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

2 participants