Skip to content

RFC: Language service extensions and tests - #9283

Merged
Wesley Wigham (weswigham) merged 11 commits into
microsoft:extensibility-modelfrom
weswigham:language-service-extensions
Jul 6, 2016
Merged

RFC: Language service extensions and tests#9283
Wesley Wigham (weswigham) merged 11 commits into
microsoft:extensibility-modelfrom
weswigham:language-service-extensions

Conversation

@weswigham

Copy link
Copy Markdown
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 Chuck Jazdzewski (@chuckjaz) for proposing the API.

So a minimal language service plugin could look like this:

import{LanguageServiceProvider}from"typescript-plugin-api";exportdefaultclassextendsLanguageServiceProvider{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",});returnprevious;}}

Comment threadsrc/services/services.ts Outdated
// 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
Copy Markdown
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
Copy Markdown
Contributor

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

Comment threadsrc/services/services.ts Outdated
// 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
Copy Markdown
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

Copy link
Copy Markdown
MemberAuthor

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

@weswigham
Wesley Wigham (weswigham) merged commit 908d9e7 into microsoft:extensibility-modelJul 6, 2016
@weswigham

Copy link
Copy Markdown
MemberAuthor

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

@microsoftMicrosoft (microsoft) locked and limited conversation to collaborators Jun 19, 2018
Sign up for freeto 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

@weswigham@chuckjaz@msftclas