Skip to content
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

Expose compiler API needed for vue #14888

Closed
wants to merge 4 commits into from
Closed

Conversation

sandersn
Copy link
Member

  1. resolveModuleName
  2. create/updateLanguageServiceSourceFile

Note that these are the hooks required to implement a typescript language service plugin as in sandersn/vue-ts-plugin. A plugin like octref/vetur that creates its own language service must also create its own host, so it only needs part (2): the create/updateLanguageServiceSourceFile hook. The host it creates has to provide an implementation of resolveModuleNames anyway, so it doesn't need (1).

If/when we decide to add these hooks, vetur will need to update the code added in vuejs/vetur#94 to avoid overwriting these functions itself.

1. resolveModuleName
2. create/updateLanguageServiceSourceFile

Note that these are the hooks required to implement a typescript
language service plugin as in sandersn/vue-ts-plugin. A plugin like
octref/vetur that creates its own language service must also create its
own host, so it only needs part (2): the
create/updateLanguageServiceSourceFile hook.
@sandersn
Copy link
Member Author

@RyanCavanaugh @mhegazy thoughts?

@RyanCavanaugh
Copy link
Member

CI's failing

return rmn(moduleName, containingFile, compilerOptions, host, cache);
}
};
function importInterested(filename: string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fileName

@@ -899,6 +899,13 @@ namespace ts {
sourceFile.scriptSnapshot = scriptSnapshot;
}

export function overrideCreateupdateLanguageServiceSourceFile(
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also recommend splitting this into createSoruceFile and upadateSourceFile.

Copy link
Member Author

Choose a reason for hiding this comment

The 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.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have two options:

  1. in LanguageServiceHost:
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 ts.createLanguageServiceSourceFile or ts.updateLanguageServiceSourceFile, we can just check the host if it supports these APIs.

  1. users can wrap the DocumentRegistry for the language service, and do the needed work in acquireDocument and updateDocument.

@@ -102,6 +102,13 @@ namespace ts.server {
export interface PluginModule {
create(createInfo: PluginCreateInfo): LanguageService;
getExternalFiles?(proj: Project): string[];
resolveModules?(createInfo: PluginCreateInfo): PluginResolveModules;
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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 resolveModuleNames on the language service host directly?

Instead, override resolveModuleNames in the provided language service
host. This is not technically part of the API, but works fine in the
current implementation.
@sandersn
Copy link
Member Author

After much discussion with @mhegazy, we couldn't figure out a non-global way to override create/updateLanguageServiceSourceFile. I'll close this PR for now and vetur (for example) will continue to override create/update globally.

@sandersn sandersn closed this Mar 30, 2017
@mhegazy mhegazy deleted the expose-compiler-API-for-vue branch November 2, 2017 21:04
@microsoft microsoft locked and limited conversation to collaborators Jun 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants