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

RFC: Language service extensions and tests #9283

Merged

Conversation

weswigham
Copy link
Member

Continuing from #9038.

This adds language service extensions to the extension API (additionally, extensions should start functioning in language server contexts).

Language server plugins are expected to have any of the publicly useful members of the language service (which they then override), and/or any of those names plus the string Filter (which they then chain together). Props to @chuckjaz for proposing the API.

So a minimal language service plugin could look like this:

import {LanguageServiceProvider} from "typescript-plugin-api";

export default class extends LanguageServiceProvider {
    constructor(ts, host, service, registry, args) { super(ts, host, service, registry, args); }
    getProgramDiagnosticsFilter(previous) {
        previous.push({
            file: undefined,
            start: undefined,
            length: undefined,
            messageText: "Test language service plugin loaded!",
            category: 2,
            code: "test-plugin-loaded",
        });
        return previous;
    }
}

// prior to the host receiving it. The TypeScript language service is invoked and the
// result is passed to the plugin as the value of the previous parameter. If more than one
// plugin is registered, the plugins are consulted in the order they are returned from the
// host. The value passed in as previous is the result returned by the prior plugin. If a
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider replacing host with Program.getCompilerExtensions() as my proposal had the language service host returning the extensions but this PR gets them from the program.

@chuckjaz
Copy link
Contributor

Thanks for taking this on! I left some minor comments.

// be returned by the TypeScript language service. If a plugin returns a defined results
// (that is, is not undefined) then that result is used instead of invoking the
// corresponding TypeScript method. If multiple plugins are registered, they are
// consulted in the order they are returned from the host. The first defined result
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider replacing host with program or Program.getCompilerExtensions().

@weswigham weswigham force-pushed the language-service-extensions branch from 5ab8d7a to a7ae427 Compare June 21, 2016 00:39
@weswigham weswigham mentioned this pull request Jun 21, 2016
6 tasks
@weswigham
Copy link
Member Author

@billti I'd really appreciate it if you'd take a look at this.

@weswigham weswigham force-pushed the language-service-extensions branch from 69c1fd5 to 80d89fb Compare June 28, 2016 19:38
@weswigham weswigham merged commit 908d9e7 into microsoft:extensibility-model Jul 6, 2016
@weswigham
Copy link
Member Author

This has been folded into the base PR, since the API design is (relatively) stable (and merging in changes from the base to this PR was beginning to be a pain).

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 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.

3 participants