File tree Expand file tree Collapse file tree 2 files changed +21
-7
lines changed
packages/typescript-plugin/src Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -7,8 +7,8 @@ import type ts from 'typescript/lib/tsserverlibrary';
7
7
import { ConfigManager , Configuration } from './config-manager' ;
8
8
import { ProjectSvelteFilesManager } from './project-svelte-files' ;
9
9
import {
10
- getConfigPathForProject ,
11
10
getProjectDirectory ,
11
+ getProjectParsedCommandLine ,
12
12
importSvelteCompiler ,
13
13
isSvelteProject
14
14
} from './utils' ;
@@ -47,11 +47,7 @@ function init(modules: { typescript: typeof ts }): ts.server.PluginModule {
47
47
logger . log ( info . config ) ;
48
48
}
49
49
50
- // This call the ConfiguredProject.getParsedCommandLine
51
- // where it'll try to load the cached version of the parsedCommandLine
52
- const parsedCommandLine = info . languageServiceHost . getParsedCommandLine ?.(
53
- getConfigPathForProject ( info . project )
54
- ) ;
50
+ const parsedCommandLine = getProjectParsedCommandLine ( info . project ) ;
55
51
56
52
// For some reason it's no longer enough to patch this at the projectService level, so we do it here, too
57
53
// TODO investigate if we can use the script snapshot for all Svelte files, too, enabling Svelte file
Original file line number Diff line number Diff line change @@ -260,7 +260,12 @@ export function isSvelteProject(project: ts.server.Project) {
260
260
// The solution project is mostly just a container we don't need to patch it
261
261
// and having any files in this project cause TSServer to send config error while it originally won't
262
262
if ( ( project as any ) . isSolution ?.( ) ) {
263
- return false ;
263
+ // In TypeScript before 5.7, the project files were added later than plugin loading
264
+ // so we need to also check if the parsedCommandLine includes any files
265
+ const parsedCommandLine = getProjectParsedCommandLine ( project ) ;
266
+ if ( parsedCommandLine ?. fileNames . length === 0 ) {
267
+ return false ;
268
+ }
264
269
}
265
270
266
271
const projectDirectory = getProjectDirectory ( project ) ;
@@ -313,3 +318,16 @@ export function importSvelteCompiler(
313
318
// ignore
314
319
}
315
320
}
321
+
322
+ /**
323
+ * This call the ConfiguredProject.getParsedCommandLine
324
+ * where it'll try to load the cached version of the parsedCommandLine
325
+ */
326
+ export function getProjectParsedCommandLine ( project : ts . server . Project ) {
327
+ const configPath = getConfigPathForProject ( project ) ;
328
+ const parsedCommandLine = ( project as ts . LanguageServiceHost ) . getParsedCommandLine ?.(
329
+ configPath
330
+ ) ;
331
+
332
+ return parsedCommandLine ;
333
+ }
You can’t perform that action at this time.
0 commit comments