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

Inline completions #1190

Merged
merged 12 commits into from
May 22, 2023
Merged

Inline completions #1190

merged 12 commits into from
May 22, 2023

Conversation

c-claeys
Copy link
Contributor

This is an initial pass per the discussion in microsoft/language-server-protocol#1529 I primarily modeled it after the existing VSCode API. I'm opening a PR for language-server-protocol in parallel.

I copied the metaModel.json changes from the other repo, so it looks like some spell/grammar changes were picked up too.

@dbaeumer
Copy link
Member

Thanks a lot for the PR. Looks overall very good.


const inlineCompletionItem = new code.InlineCompletionItem(insertText, asRange(item.range), command);

if (item.filterText) {inlineCompletionItem.filterText = item.filterText;}
Copy link
Member

Choose a reason for hiding this comment

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

Minor :-). Missing space

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -23,7 +23,7 @@ import semverSatisfies = require('semver/functions/satisfies');
export * from 'vscode-languageserver-protocol/node';
export * from '../common/api';

const REQUIRED_VSCODE_VERSION = '^1.67.0'; // do not change format, updated by `updateVSCode` script
const REQUIRED_VSCODE_VERSION = '^1.68.0'; // do not change format, updated by `updateVSCode` script
Copy link
Member

Choose a reason for hiding this comment

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

This is normally updated via a tool.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used the tool but think I discarded some changes. Re-ran it.

@@ -1,11 +1,11 @@
{
"name": "vscode-languageclient",
"description": "VSCode Language client implementation",
"version": "8.1.0-next.6",
"version": "8.1.0-next.7",
Copy link
Member

Choose a reason for hiding this comment

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

I released 8.1.0 yesterday. So you need to rebase and move to 8.2.0-next.1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -121,6 +121,8 @@ import {
DidCloseNotebookDocumentNotification
} from './protocol.notebook';

import {InlineCompletionClientCapabilities, InlineCompletionOptions, InlineCompletionParams, InlineCompletionRegistrationOptions, InlineCompletionRequest} from './protocol.inlineCompletion';
Copy link
Member

Choose a reason for hiding this comment

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

Space

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

/**
* The format of the insert text. The format applies to the `insertText`. If omitted defaults to `InsertTextFormat.PlainText`.
*/
insertTextFormat?: InsertTextFormat;
Copy link
Member

Choose a reason for hiding this comment

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

I would move this up under insertText.

We could also start thinking about introducing a complex string type that encapsulates this. E.g.

type StringContent = {
	kind: 'string' | 'snippet';
	value: string;
}

The reason why we didn't do that for completion items was backwards compatibility.

@aeschli do you have thoghts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved. Happy to alter this to use the complex type instead.

Copy link
Member

Choose a reason for hiding this comment

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

@aeschli friendly ping. I am actually leaning more towards adding the StringContent type.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, agree, makes sense to avoid the additional property as don't need to be backward compatible.
In vscode.d.ts there's the SnippetString.
So I suggest: insertText: string | SnippetString;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the SnippetString type, removed the InsertTextFormat usage, and updated the Inline Completions to use the new type.


export namespace InlineCompletionItem {
export function create(insertText: string, filterText?: string, range?: Range, command?: Command, insertTextFormat?: InsertTextFormat): InlineCompletionItem {
return {insertText, filterText, range, command, insertTextFormat};
Copy link
Member

Choose a reason for hiding this comment

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

spacing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


export namespace InlineCompletionList {
export function create(items: InlineCompletionItem[]): InlineCompletionList {
return {items};
Copy link
Member

Choose a reason for hiding this comment

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

spacing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


export namespace SelectedCompletionInfo {
export function create(range: Range, text: string): SelectedCompletionInfo {
return {range, text};
Copy link
Member

Choose a reason for hiding this comment

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

spacing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


export namespace InlineCompletionContext{
export function create(triggerKind: InlineCompletionTriggerKind, selectedCompletionInfo?: SelectedCompletionInfo): InlineCompletionContext {
return {triggerKind, selectedCompletionInfo};
Copy link
Member

Choose a reason for hiding this comment

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

spacing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@c-claeys
Copy link
Contributor Author

Updated metaModel.json via the script

@c-claeys c-claeys requested a review from dbaeumer February 17, 2023 20:08
@dbaeumer
Copy link
Member

The version number of types and protocol need to be moved to 3.18.0-next.1 and correctly referenced in the upstream packages.

@@ -1739,6 +1742,7 @@ export abstract class BaseLanguageClient implements FeatureClient<Middleware, La
this.registerFeature(new InlayHintsFeature(this));
this.registerFeature(new DiagnosticFeature(this));
this.registerFeature(new NotebookDocumentSyncFeature(this));
this.registerFeature(new InlineCompletionItemFeature(this));
Copy link
Member

Choose a reason for hiding this comment

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

Actually I overlooked that in the first review. We in general first add new features as proposed even if they are already final in VS Code since we need to allow the LSP community to provide feedback as well.

So we need to add the feater first in ProposedFeatures.createAll and a client needs to call registerProposedFeatures to make use of it.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry for not noticing this earlier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No worries. Done.

export type Languages = _Languages & CallHierarchy & SemanticTokensFeatureShape & LinkedEditingRangeFeatureShape & TypeHierarchyFeatureShape & InlineValueFeatureShape & InlayHintFeatureShape & DiagnosticFeatureShape & MonikerFeatureShape;
const LanguagesImpl: new () => Languages = MonikerFeature(DiagnosticFeature(InlayHintFeature(InlineValueFeature(TypeHierarchyFeature(LinkedEditingRangeFeature(SemanticTokensFeature(CallHierarchyFeature(_LanguagesImpl)))))))) as (new () => Languages);
export type Languages = _Languages & CallHierarchy & SemanticTokensFeatureShape & LinkedEditingRangeFeatureShape & TypeHierarchyFeatureShape & InlineValueFeatureShape & InlayHintFeatureShape & DiagnosticFeatureShape & MonikerFeatureShape & InlineCompletionFeatureShape;
const LanguagesImpl: new () => Languages = InlineCompletionFeature(MonikerFeature(DiagnosticFeature(InlayHintFeature(InlineValueFeature(TypeHierarchyFeature(LinkedEditingRangeFeature(SemanticTokensFeature(CallHierarchyFeature(_LanguagesImpl))))))))) as (new () => Languages);
Copy link
Member

Choose a reason for hiding this comment

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

Same as with the client. The InlineCompletionFeature first must come as a proposed feature users need to opt in in the beginning. Registering a propsed feature on the server is a little bit more tricky and I can help with this. An example can be found here: https://github.com/microsoft/vscode-languageserver-node/blob/9dd23aa6d06cada41964f972021924503929bfdd/server/src/common/api.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I did this correctly but the need to cast createConnection in testServer.ts gave me some pause. Let me know if it should be adjusted further.

@dbaeumer
Copy link
Member

@c-claeys can you please make the changes @aeschli suggested.

@c-claeys c-claeys force-pushed the inline-completions branch from 66c1eb2 to e7db9b9 Compare March 2, 2023 16:56
@c-claeys c-claeys requested a review from dbaeumer March 2, 2023 17:00
Copy link
Member

@dbaeumer dbaeumer left a comment

Choose a reason for hiding this comment

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

Could you please do these two changes.

*
* @since 3.18.0
*/
export interface SnippetString {
Copy link
Member

Choose a reason for hiding this comment

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

To make this easier to extend for the future we should have something more like

export interface StringValue {
	kind: 'snippet';
	value: string;
}

Otherwise it is very hard to evolve in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@c-claeys c-claeys force-pushed the inline-completions branch from e7db9b9 to 5167b24 Compare March 9, 2023 12:44
@c-claeys c-claeys requested a review from dbaeumer March 9, 2023 12:45

/**
* Represents a collection of {@link InlineCompletionItem inline completion items} to be presented in the editor.
*/
Copy link
Member

Choose a reason for hiding this comment

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

@SInCE 3.18.0
@proposed

missing

Copy link
Member

Choose a reason for hiding this comment

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

@c-claeys very nice work. Highly appreciated. One last minor change request for a missing @SInCE / @proposed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you and you're welcome. Of course, sorry I missed it. Done.

@c-claeys c-claeys force-pushed the inline-completions branch from 5167b24 to f2d1ba7 Compare March 14, 2023 18:30
@c-claeys c-claeys requested a review from dbaeumer March 14, 2023 18:39
@dbaeumer dbaeumer enabled auto-merge (squash) March 16, 2023 08:10
aeschli
aeschli previously approved these changes Mar 16, 2023
@aeschli
Copy link
Contributor

aeschli commented Mar 16, 2023

Approved.
As discussed with @dbaeumer I suggest to improve StringValue and have
type SnippetString = { kind: 'snippet', value: string }
so we can write insertText: string | SnippetString;
so it's clear that SnippetString is the only thing supported (for now)

@dbaeumer
Copy link
Member

@c-claeys I just noticed that now and it is somehow embarrassing for me: your changes do not compile in the pipeline. The reason is that you already increased the package versions which of course doesn't work since they are not published to npm yet. So you need to undo all the changes were you:

  • you upgraded/changed the version of a package to a -next version
  • were you upgraded the version of a dependency of a package which is maintained in this repository. For example: vscode-languageserver-protocol
  • it is fine to upgrade the engine version of a dependency to the @types/vscode.

You can always check locally if the pipeline will compile by doing:

> git clean -xfd .
> npm install
> npm run symlink
> npm run test

We have a different publish pipeline that increases the version numbers which is not public.

Copy link
Member

@dbaeumer dbaeumer left a comment

Choose a reason for hiding this comment

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

See latest comment about the version numbers.

auto-merge was automatically disabled March 31, 2023 11:36

Head branch was pushed to by a user without write access

@c-claeys c-claeys force-pushed the inline-completions branch from d17c7f7 to 59d676d Compare March 31, 2023 11:36
@c-claeys c-claeys requested a review from dbaeumer March 31, 2023 11:37
@c-claeys
Copy link
Contributor Author

I'm fairly certain I addressed the version changes as you requested. That said, npm run test is failing like:

> [email protected] test
> node ../node_modules/mocha/bin/_mocha

Error: No test files found
/<path>/vscode-languageserver-node/types

> [email protected] test
> node ../node_modules/mocha/bin/_mocha

Error: No test files found: "lib/umd/test"
/<path>/vscode-languageserver-node/jsonrpc

I couldn't regen the metaModel either, even after running npm run compile:metaModelTool first. Maybe that needs your publish workflow to happen first? Let me know if I need to make further modifications to my PR

@mroch
Copy link
Contributor

mroch commented Apr 20, 2023

any ideas on how to implement handleDidShowCompletionItem and handleDidPartiallyAcceptCompletionItem on InlineCompletionItemProvider?

@dbaeumer
Copy link
Member

@mroch these two callbacks are proposed in VS Code and in LSP I usually don't adapt proposed API since a library can't opt into using it only extensions.

@dbaeumer dbaeumer merged commit cc7666f into microsoft:main May 22, 2023
awschristou added a commit to aws/aws-toolkit-common that referenced this pull request Jul 7, 2023
…dations (#526)

This change adds a concept language server that provides code recommendations from CodeWhisperer. The recommendations are returned through code completions and inline completion.

The sample VS Code extension has been updated to support this language server when editing typescript files. This is accomplished by introducing an inline completion provider, which wraps the concept language server.

At this time, inline completion is not a part of the language server protocol. VS Code has an extensibility API for inline completion, and a proposal is part of the next protocol version 3.18 (microsoft/language-server-protocol#1673). This proposal is modelled after the extensibility API.

A likely implementation of the protocol is proposed in microsoft/vscode-languageserver-node#1190, and portions of this change leverage the shapes defined in that proposal. This way, if or when inline completion is a part of the spec, we could update code to reference `vscode-languageserver` related types with little effort.

This concept uses IAM credentials with CodeWhisperer as a way to get up and iterating quickly. In future work we will want to switch over to using bearer tokens, like the AWS Toolkit for VS Code does.

The CodeWhisperer service client was produced using the AWS Toolkit for VS Code's client generator (https://github.com/aws/aws-toolkit-vscode/blob/master/scripts/build/generateServiceClient.ts)

This language server is being submitted so that we can perform additional experimentation such as:
- verifying browser compatibility
- exploring the UX around surfacing code recommendations
- future bearer token support
awschristou added a commit to aws/language-servers that referenced this pull request Aug 11, 2023
…dations (#526)

This change adds a concept language server that provides code recommendations from CodeWhisperer. The recommendations are returned through code completions and inline completion.

The sample VS Code extension has been updated to support this language server when editing typescript files. This is accomplished by introducing an inline completion provider, which wraps the concept language server.

At this time, inline completion is not a part of the language server protocol. VS Code has an extensibility API for inline completion, and a proposal is part of the next protocol version 3.18 (microsoft/language-server-protocol#1673). This proposal is modelled after the extensibility API.

A likely implementation of the protocol is proposed in microsoft/vscode-languageserver-node#1190, and portions of this change leverage the shapes defined in that proposal. This way, if or when inline completion is a part of the spec, we could update code to reference `vscode-languageserver` related types with little effort.

This concept uses IAM credentials with CodeWhisperer as a way to get up and iterating quickly. In future work we will want to switch over to using bearer tokens, like the AWS Toolkit for VS Code does.

The CodeWhisperer service client was produced using the AWS Toolkit for VS Code's client generator (https://github.com/aws/aws-toolkit-vscode/blob/master/scripts/build/generateServiceClient.ts)

This language server is being submitted so that we can perform additional experimentation such as:
- verifying browser compatibility
- exploring the UX around surfacing code recommendations
- future bearer token support
@c-claeys c-claeys deleted the inline-completions branch September 12, 2023 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants