Skip to content

Reactivity analysis attaches a .js file to a tsconfig project that doesn't include it, so tsserver answers nothing for that file #6325

Done

Description

@daviwil

Vue - Official extension or vue-tsc version

3.3.14 (also 3.3.13)

VSCode version

Not VS Code: Eclipse Theia 1.76 with VS Code's built-in TypeScript extension 1.95.3. The tsserver-only script below reproduces it without an editor.

Vue version

3.5.22

TypeScript version

5.9.3 (also 5.6.3, bundled with the TypeScript extension 1.95.3)

package.json dependencies

{
  "type": "module",
  "dependencies": { "vue": "3.5.22" },
  "devDependencies": { "@vue/tsconfig": "0.7.0", "typescript": "5.9.3" }
}

Steps to reproduce

A JS entry file in a project whose tsconfig.app.json has no allowJs, as in a create-vue TypeScript scaffold with main.ts renamed to main.js:

  • tsconfig.json: { "files": [], "references": [{ "path": "./tsconfig.app.json" }] }
  • tsconfig.app.json: { "extends": "@vue/tsconfig/tsconfig.dom.json", "include": ["src/**/*", "src/**/*.vue"] }
  • src/App.vue: <script setup>const msg = 'hello'</script><template><h1>{{ msg }}</h1></template>
  • src/main.js, four lines:
import { createApp } from 'vue'
import App from './App.vue'

createApp(App).mount('#app')

Run npm install, then node repro.cjs <Vue.volar extension dir> node_modules/typescript/lib/tsserver.js App.vue,main.js. The script (below) starts tsserver with patch-tsserver.js and both plugin packs, opens both files, sends _vue:getReactivityAnalysis in the given order, and asks quickinfo on createApp:

main.js project after open: /dev/null/inferredProject1*
main.js project after _vue:getReactivityAnalysis(App.vue): /dev/null/inferredProject1*
main.js project after _vue:getReactivityAnalysis(main.js): /work/tsconfig.app.json
quickinfo on createApp: Error processing request. Could not find source file: '/work/src/main.js'.

With the order main.js,App.vue, main.js stays in inferredProject1* and quickinfo answers.

In the editor: with App.vue active first and then main.js, hovering createApp shows nothing and createApp(App). offers no members. Restarting the TS server fixes it until a .vue file is analyzed first again.

repro.cjs
// node repro.cjs <Vue.volar extension dir> <tsserver.js> <order, e.g. App.vue,main.js>
const { spawn } = require('child_process');
const fs = require('fs');
const path = require('path');

const [ext, tsserver, order = 'App.vue,main.js'] = process.argv.slice(2);
const root = __dirname;
const p = spawn(process.execPath, [
  '--require', path.join(ext, 'dist/patch-tsserver.js'), tsserver,
  '--useInferredProjectPerProjectRoot', '--disableAutomaticTypingAcquisition',
  '--globalPlugins', 'vue-reactivity-analysis-plugin-pack,vue-typescript-plugin-pack',
  '--pluginProbeLocations', ext,
], { stdio: ['pipe', 'pipe', 'inherit'] });

let seq = 0, buf = Buffer.alloc(0);
const pending = new Map();
p.stdout.on('data', (d) => {
  buf = Buffer.concat([buf, d]);
  for (;;) {
    const h = buf.indexOf('\r\n\r\n');
    if (h < 0) return;
    const len = +/Content-Length: (\d+)/.exec(buf.slice(0, h).toString())[1];
    if (buf.length < h + 4 + len) return;
    const msg = JSON.parse(buf.slice(h + 4, h + 4 + len).toString());
    buf = buf.slice(h + 4 + len);
    if (msg.type === 'response' && pending.has(msg.request_seq)) pending.get(msg.request_seq)(msg);
  }
});
const req = (command, args) => new Promise((resolve) => {
  pending.set(++seq, resolve);
  p.stdin.write(JSON.stringify({ seq, type: 'request', command, arguments: args }) + '\n');
});
const file = (name) => path.join(root, 'src', name);
const projectOf = async (name) => (await req('projectInfo', { file: file(name), needFileNameList: false })).body.configFileName;

(async () => {
  await req('compilerOptionsForInferredProjects', { options: { allowJs: true, module: 'ESNext', moduleResolution: 'Bundler', target: 'ES2022' } });
  await req('updateOpen', {
    openFiles: ['main.js', 'App.vue'].map((name) => ({ file: file(name), fileContent: fs.readFileSync(file(name), 'utf8'), projectRootPath: root })),
  });
  console.log('main.js project after open:', await projectOf('main.js'));
  for (const name of order.split(',')) {
    await req('_vue:getReactivityAnalysis', [file(name), 0]);
    console.log(`main.js project after _vue:getReactivityAnalysis(${name}):`, await projectOf('main.js'));
  }
  const qi = await req('quickinfo', { file: file('main.js'), line: 4, offset: 1 });
  console.log('quickinfo on createApp:', qi.success ? qi.body.displayString.split('\n')[0] : qi.message.split('\n')[0]);
  p.kill();
})();

What is expected?

src/main.js stays in its inferred project, and hover and completion work whichever file was analyzed first.

What is actually happening?

After _vue:getReactivityAnalysis runs for a .vue file and then for main.js, tsserver moves main.js into tsconfig.app.json, whose program doesn't contain it. Every semantic request for main.js then fails with "Could not find source file".

Any additional comments?

The _vue:getReactivityAnalysis handler in reactivity-analysis-plugin.js creates one module-level language service on its first call, bound to the language of that call's project. My reading is that later files are then read through the first project's host, and tsserver's getScriptSnapshot attaches them to that project, which becomes their default project. Clearing the cached service at the start of each call (_=void 0) makes the App.vue,main.js order pass, so caching it per project should fix this.

Workaround: "vue.editor.reactivityVisualization": false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions