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';
77import { ConfigManager , Configuration } from './config-manager' ;
88import { ProjectSvelteFilesManager } from './project-svelte-files' ;
99import {
10- getConfigPathForProject ,
1110 getProjectDirectory ,
11+ getProjectParsedCommandLine ,
1212 importSvelteCompiler ,
1313 isSvelteProject
1414} from './utils' ;
@@ -47,11 +47,7 @@ function init(modules: { typescript: typeof ts }): ts.server.PluginModule {
4747 logger . log ( info . config ) ;
4848 }
4949
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 ) ;
5551
5652 // For some reason it's no longer enough to patch this at the projectService level, so we do it here, too
5753 // 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) {
260260 // The solution project is mostly just a container we don't need to patch it
261261 // and having any files in this project cause TSServer to send config error while it originally won't
262262 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+ }
264269 }
265270
266271 const projectDirectory = getProjectDirectory ( project ) ;
@@ -313,3 +318,16 @@ export function importSvelteCompiler(
313318 // ignore
314319 }
315320}
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