-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7de75d3
commit 376e0d9
Showing
7 changed files
with
64 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { createConnection, startTypeScriptServer } from '@volar/language-server/node'; | ||
import { createConnection, startSimpleServer } from '@volar/language-server/node'; | ||
import { createPlugin } from './languageServerPlugin.js'; | ||
|
||
const connection = createConnection(); | ||
const plugin = createPlugin(connection); | ||
|
||
startTypeScriptServer(connection, plugin); | ||
startSimpleServer(connection, plugin); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,9 @@ | ||
import { createFileProvider } from '@volar/language-core'; | ||
import { | ||
decorateLanguageService, | ||
decorateLanguageServiceHost, | ||
searchExternalFiles, | ||
} from '@volar/typescript'; | ||
import * as semver from 'semver'; | ||
import type ts from 'typescript/lib/tsserverlibrary'; | ||
import { createTSServerPlugin } from '@volar/typescript/lib/starters/createTSServerPlugin.js'; | ||
import { getLanguageModule } from './language.js'; | ||
|
||
const externalFiles = new WeakMap<ts.server.Project, string[]>(); | ||
|
||
const init: ts.server.PluginModuleFactory = (modules) => { | ||
const { typescript: ts } = modules; | ||
const pluginModule: ts.server.PluginModule = { | ||
create(info) { | ||
const virtualFiles = createFileProvider( | ||
[getLanguageModule(ts)], | ||
ts.sys.useCaseSensitiveFileNames, | ||
() => {} | ||
); | ||
|
||
decorateLanguageService(virtualFiles, info.languageService); | ||
decorateLanguageServiceHost(virtualFiles, info.languageServiceHost, ts, ['.astro']); | ||
|
||
if (semver.lt(ts.version, '5.3.0')) { | ||
// HACK: AutoImportProviderProject's script kind does not match the one of the language service host here | ||
// this causes TypeScript to throw and crash. So, we'll fake being a TS file here for now until they fix it | ||
// Fixed by https://github.com/microsoft/TypeScript/pull/55716 | ||
const getScriptKind = info.languageServiceHost.getScriptKind?.bind( | ||
info.languageServiceHost.getScriptKind | ||
); | ||
if (getScriptKind) { | ||
info.languageServiceHost.getScriptKind = (fileName) => { | ||
if (fileName.endsWith('.astro')) { | ||
return ts.ScriptKind.TS; | ||
} | ||
return getScriptKind(fileName); | ||
}; | ||
} | ||
} | ||
|
||
return info.languageService; | ||
}, | ||
getExternalFiles(project, updateLevel = 0) { | ||
if ( | ||
// @ts-expect-error wait for TS 5.3 | ||
updateLevel >= (1 satisfies ts.ProgramUpdateLevel.RootNamesAndUpdate) || | ||
!externalFiles.has(project) | ||
) { | ||
const oldFiles = externalFiles.get(project); | ||
const newFiles = searchExternalFiles(ts, project, ['.astro']); | ||
externalFiles.set(project, newFiles); | ||
if (oldFiles && !arrayItemsEqual(oldFiles, newFiles)) { | ||
project.refreshDiagnostics(); | ||
} | ||
} | ||
return externalFiles.get(project)!; | ||
}, | ||
export = createTSServerPlugin((ts) => { | ||
return { | ||
extensions: ['.astro'], | ||
languagePlugins: [getLanguageModule(ts)], | ||
}; | ||
return pluginModule; | ||
}; | ||
|
||
function arrayItemsEqual(a: string[], b: string[]) { | ||
if (a.length !== b.length) { | ||
return false; | ||
} | ||
const set = new Set(a); | ||
for (const file of b) { | ||
if (!set.has(file)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
export = init; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.