-
Notifications
You must be signed in to change notification settings - Fork 13k
Expose compiler API needed for vue #14888
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,13 @@ namespace ts.server { | |
export interface PluginModule { | ||
create(createInfo: PluginCreateInfo): LanguageService; | ||
getExternalFiles?(proj: Project): string[]; | ||
resolveModules?(createInfo: PluginCreateInfo): PluginResolveModules; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the plugin already has access to the lshost, it can just override resolveModule directly. not sure i see the need for this new API. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically it does, but I'm not sure whether the API guarantees it. Regardless, it gets rid of a lot of code. @RyanCavanaugh can you take a look at the new commits that override |
||
} | ||
|
||
export type ModuleResolver = (moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache) => ResolvedModuleWithFailedLookupLocations; | ||
|
||
export type PluginResolveModules = { | ||
(plugin: ModuleResolver): ModuleResolver; | ||
} | ||
|
||
export interface PluginModuleFactory { | ||
|
@@ -904,6 +911,9 @@ namespace ts.server { | |
|
||
const pluginModule = pluginModuleFactory({ typescript: ts }); | ||
this.languageService = pluginModule.create(info); | ||
if (pluginModule.resolveModules) { | ||
this.lsHost.overrideResolveModuleName(pluginModule.resolveModules(info)); | ||
} | ||
this.plugins.push(pluginModule); | ||
} | ||
catch (e) { | ||
|
@@ -1083,4 +1093,4 @@ namespace ts.server { | |
this.typeAcquisition = newTypeAcquisition; | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -899,6 +899,13 @@ namespace ts { | |
sourceFile.scriptSnapshot = scriptSnapshot; | ||
} | ||
|
||
export function overrideCreateupdateLanguageServiceSourceFile( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be a LanguageServiceHost optional functions. we do not want to override this for all instances of the language service. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would also recommend splitting this into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are global functions, so I'm not sure how to avoid overriding them for all instances of the language service. (That was probably the cause of the CI failures; bad overrides are also global.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have two options:
export interface LanguageServiceHost {
...
createSourceFile?(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean, scriptKind?: ScriptKind): SourceFile;
updateSourceFile?(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
....
} Then in the language service, in places where we call
|
||
create: (fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean, scriptKind?: ScriptKind, cheat?: string) => SourceFile, | ||
update: (sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean, cheat?: string) => SourceFile) { | ||
ts.createLanguageServiceSourceFile = create; | ||
ts.updateLanguageServiceSourceFile = update; | ||
} | ||
|
||
export function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean, scriptKind?: ScriptKind): SourceFile { | ||
const text = scriptSnapshot.getText(0, scriptSnapshot.getLength()); | ||
const sourceFile = createSourceFile(fileName, text, scriptTarget, setNodeParents, scriptKind); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/// <reference path="../fourslash.ts"/> | ||
|
||
// @Filename: tsconfig.json | ||
//// { | ||
//// "compilerOptions": { | ||
//// "allowNonTsExtensions": true, | ||
//// "plugins": [ | ||
//// { "name": "mock-vue" } | ||
//// ] | ||
//// }, | ||
//// "files": ["a.vue"] | ||
//// } | ||
|
||
// Note: This test does *not* implement the correct vue transformation. | ||
// So it's other.data.property, not other.property or other.$data.property | ||
// @Filename: other.vue | ||
////<template> | ||
////</template> | ||
////<script> | ||
////export default { | ||
//// data: { property: "Example" } | ||
////} | ||
////</script> | ||
////<style> | ||
////</style> | ||
|
||
|
||
// @Filename: a.vue | ||
////<template> | ||
////</template> | ||
////<script> | ||
////import other from './other.vue' | ||
//// other.data.property/**/ | ||
////export default { | ||
//// data: { greeting: "Hello" } | ||
////} | ||
////</script> | ||
////<style> | ||
////</style> | ||
|
||
// LS shouldn't crash/fail if a plugin fails to init correctly | ||
goTo.marker(); | ||
verify.quickInfoIs('(property) property: string'); | ||
verify.numberOfErrorsInCurrentFile(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fileName