-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Support for copilot-generated summaries in quick info. (On-the-fly docs) #12552
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
Merged
Merged
Changes from 48 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
0eac8bf
initial on-the-fly docs implementation for vscode
spebl 93d7bb0
merge from main
spebl 2667ec5
add localization support
spebl fb310c8
add support for icons in hover
spebl 433f22d
add support for feature flag control
spebl 7ec62d9
add setting and strings
spebl 7a41841
fix settings when copilot models load later and fix showing copilot w…
spebl db42258
'otf docs' -> 'copilot hover' in naming conventions and strings. fixe…
spebl c73a589
fix spacing
spebl aa6779c
merge from main
spebl 28390f1
reset vscode version
spebl 3d5b7db
merge from main
spebl bd1eb43
merge from main
spebl d9c74c3
merge from main
spebl c31c4ab
merge from main
spebl 9742465
fix formatting
spebl 3bb4f1f
merge from main
spebl 1cf0785
merge from main
spebl 6076ca9
swap to using new copilot hover provider as to not interfere with exi…
spebl fd7095d
Add RAI disclaimers
benmcmorran 9e1a547
merge from vscode
spebl d6a340f
merge from upstream
spebl f8cdde6
Copilot summary should now only show up when there is already hover c…
spebl 713f430
Merge branch 'main' into dev/spebl/otfdocs
spebl 10fb3cf
move AI inaccuracy warning to hover tooltip, add sparkle to load, che…
spebl 3a0b8d8
prompt user to reload workspace when changing copilot hover option
spebl 1be1fcc
merge from upstream
spebl ceb9f8e
merge from main
spebl 9376135
merge from main
spebl ba5f149
merge from main
spebl 8707994
Merge branch 'main' into dev/spebl/otfdocs
spebl 1b37fd1
track and pass cancellation token + fix copilot hover showing up befo…
spebl f8fc500
Merge branch 'dev/spebl/otfdocs' of https://github.com/Microsoft/vsco…
spebl 223d52b
better handling of intentional cancellation by user
spebl c055ce2
ensure tokens and cancellation are all in sync between copilot hover …
spebl 3af533d
Merge branch 'main' into dev/spebl/otfdocs
spebl ad991c6
Merge branch 'main' into dev/spebl/otfdocs
spebl 76000c7
swap to use same params for copilot hover info as text document posit…
spebl 0fc52ed
Merge branch 'main' of https://github.com/Microsoft/vscode-cpptools i…
spebl 1788813
Merge branch 'dev/spebl/otfdocs' of https://github.com/Microsoft/vsco…
spebl ec844a3
Merge branch 'main' of https://github.com/Microsoft/vscode-cpptools i…
spebl 9bd009a
update copilot hover setting but still allow for opt out
spebl 9a67c9c
add basic telemetry for usage and failures
spebl 6704c47
explicitly mark defaultError as string
spebl 4a68683
give localize() the string literal it desires
spebl e083fa3
Merge branch 'main' of https://github.com/Microsoft/vscode-cpptools i…
spebl 0ec4890
dont log error for symbols with no context and dont log generic error…
spebl 3724b10
Merge branch 'main' into dev/spebl/otfdocs
spebl 0913dac
use default client instead of active client to support additional wor…
spebl 3893c20
Merge branch 'dev/spebl/otfdocs' of https://github.com/Microsoft/vsco…
spebl ba4d436
enable trusted markdown based on copilot hover setting
spebl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
Extension/src/LanguageServer/Providers/CopilotHoverProvider.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| /* -------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All Rights Reserved. | ||
| * See 'LICENSE' in the project root for license information. | ||
| * ------------------------------------------------------------------------------------------ */ | ||
| import * as vscode from 'vscode'; | ||
| import { Position, ResponseError } from 'vscode-languageclient'; | ||
| import * as nls from 'vscode-nls'; | ||
| import { DefaultClient, GetCopilotHoverInfoParams, GetCopilotHoverInfoRequest } from '../client'; | ||
| import { RequestCancelled, ServerCancelled } from '../protocolFilter'; | ||
| import { CppSettings } from '../settings'; | ||
|
|
||
| nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })(); | ||
| const localize: nls.LocalizeFunc = nls.loadMessageBundle(); | ||
|
|
||
| export class CopilotHoverProvider implements vscode.HoverProvider { | ||
| private client: DefaultClient; | ||
| private currentDocument: vscode.TextDocument | undefined; | ||
| private currentPosition: vscode.Position | undefined; | ||
| private currentCancellationToken: vscode.CancellationToken | undefined; | ||
| private waiting: boolean = false; | ||
| private ready: boolean = false; | ||
| private cancelled: boolean = false; | ||
| private cancelledDocument: vscode.TextDocument | undefined; | ||
| private cancelledPosition: vscode.Position | undefined; | ||
| private content: string | undefined; | ||
| constructor(client: DefaultClient) { | ||
| this.client = client; | ||
| } | ||
|
|
||
| public async provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Promise<vscode.Hover | undefined> { | ||
| await this.client.ready; | ||
|
|
||
| const settings: CppSettings = new CppSettings(vscode.workspace.getWorkspaceFolder(document.uri)?.uri); | ||
| if (settings.hover === "disabled") { | ||
| return undefined; | ||
| } | ||
|
|
||
| const newHover = this.isNewHover(document, position); | ||
| if (newHover) { | ||
| this.reset(); | ||
| } | ||
|
|
||
| // Wait for the main hover provider to finish and confirm it has content. | ||
| const hoverProvider = this.client.getHoverProvider(); | ||
| if (!await hoverProvider?.contentReady) { | ||
| return undefined; | ||
| } | ||
|
|
||
| if (token.isCancellationRequested) { | ||
| throw new vscode.CancellationError(); | ||
| } | ||
| this.currentCancellationToken = token; | ||
|
|
||
| if (!newHover) { | ||
| if (this.ready) { | ||
| const contentMarkdown = new vscode.MarkdownString(`$(sparkle) Copilot\n\n${this.content}`, true); | ||
| return new vscode.Hover(contentMarkdown); | ||
| } | ||
| if (this.waiting) { | ||
| const loadingMarkdown = new vscode.MarkdownString("$(sparkle) $(loading~spin)", true); | ||
| return new vscode.Hover(loadingMarkdown); | ||
| } | ||
| } | ||
|
|
||
| this.currentDocument = document; | ||
| this.currentPosition = position; | ||
| const commandString = "$(sparkle) [" + localize("generate.copilot.description", "Generate Copilot summary") + "](command:C_Cpp.ShowCopilotHover \"" + localize("copilot.disclaimer", "AI-generated content may be incorrect.") + "\")"; | ||
| const commandMarkdown = new vscode.MarkdownString(commandString); | ||
| commandMarkdown.supportThemeIcons = true; | ||
| commandMarkdown.isTrusted = true; | ||
spebl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return new vscode.Hover(commandMarkdown); | ||
| } | ||
|
|
||
| public showWaiting(): void { | ||
| this.waiting = true; | ||
| } | ||
|
|
||
| public showContent(content: string): void { | ||
| this.ready = true; | ||
| this.content = content; | ||
| } | ||
|
|
||
| public getCurrentHoverDocument(): vscode.TextDocument | undefined { | ||
| return this.currentDocument; | ||
| } | ||
|
|
||
| public getCurrentHoverPosition(): vscode.Position | undefined { | ||
| return this.currentPosition; | ||
| } | ||
|
|
||
| public getCurrentHoverCancellationToken(): vscode.CancellationToken | undefined { | ||
| return this.currentCancellationToken; | ||
| } | ||
|
|
||
| public async getRequestInfo(document: vscode.TextDocument, position: vscode.Position): Promise<string> { | ||
| let requestInfo = ""; | ||
| const params: GetCopilotHoverInfoParams = { | ||
| textDocument: { uri: document.uri.toString() }, | ||
| position: Position.create(position.line, position.character) | ||
| }; | ||
|
|
||
| await this.client.ready; | ||
| if (this.currentCancellationToken?.isCancellationRequested) { | ||
| throw new vscode.CancellationError(); | ||
| } | ||
|
|
||
| try { | ||
| const response = await this.client.languageClient.sendRequest(GetCopilotHoverInfoRequest, params, this.currentCancellationToken); | ||
| requestInfo = response.content; | ||
| } catch (e: any) { | ||
| if (e instanceof ResponseError && (e.code === RequestCancelled || e.code === ServerCancelled)) { | ||
| throw new vscode.CancellationError(); | ||
| } | ||
| throw e; | ||
| } | ||
|
|
||
| return requestInfo; | ||
| } | ||
|
|
||
| public isCancelled(document: vscode.TextDocument, position: vscode.Position): boolean { | ||
| if (this.cancelled && this.cancelledDocument === document && this.cancelledPosition === position) { | ||
| // Cancellation is being acknowledged. | ||
| this.cancelled = false; | ||
| this.cancelledDocument = undefined; | ||
| this.cancelledPosition = undefined; | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public reset(): void { | ||
| // If there was a previous call, cancel it. | ||
| if (this.waiting) { | ||
| this.cancelled = true; | ||
| this.cancelledDocument = this.currentDocument; | ||
| this.cancelledPosition = this.currentPosition; | ||
| } | ||
| this.waiting = false; | ||
| this.ready = false; | ||
| this.content = undefined; | ||
| this.currentDocument = undefined; | ||
| this.currentPosition = undefined; | ||
| this.currentCancellationToken = undefined; | ||
| } | ||
|
|
||
| public isNewHover(document: vscode.TextDocument, position: vscode.Position): boolean { | ||
| return !(this.currentDocument === document && this.currentPosition?.line === position.line && (this.currentPosition?.character === position.character || this.currentPosition?.character === position.character - 1)); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.