-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12633 from microsoft/main
Merge for 1.22.0 (2nd time)
- Loading branch information
Showing
23 changed files
with
157 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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,57 @@ | ||
/* -------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All Rights Reserved. | ||
* See 'LICENSE' in the project root for license information. | ||
* ------------------------------------------------------------------------------------------ */ | ||
import * as vscode from 'vscode'; | ||
import { Position, ResponseError, TextDocumentPositionParams } from 'vscode-languageclient'; | ||
import { DefaultClient, HoverRequest } from '../client'; | ||
import { RequestCancelled, ServerCancelled } from '../protocolFilter'; | ||
import { CppSettings } from '../settings'; | ||
|
||
export class HoverProvider implements vscode.HoverProvider { | ||
private client: DefaultClient; | ||
constructor(client: DefaultClient) { | ||
this.client = client; | ||
} | ||
|
||
public async provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Promise<vscode.Hover | undefined> { | ||
const settings: CppSettings = new CppSettings(vscode.workspace.getWorkspaceFolder(document.uri)?.uri); | ||
if (settings.hover === "disabled") { | ||
return undefined; | ||
} | ||
const params: TextDocumentPositionParams = { | ||
textDocument: { uri: document.uri.toString() }, | ||
position: Position.create(position.line, position.character) | ||
}; | ||
await this.client.ready; | ||
let hoverResult: vscode.Hover; | ||
try { | ||
hoverResult = await this.client.languageClient.sendRequest(HoverRequest, params, token); | ||
} catch (e: any) { | ||
if (e instanceof ResponseError && (e.code === RequestCancelled || e.code === ServerCancelled)) { | ||
throw new vscode.CancellationError(); | ||
} | ||
throw e; | ||
} | ||
if (token.isCancellationRequested) { | ||
throw new vscode.CancellationError(); | ||
} | ||
// VS Code doesn't like the raw objects returned via RPC, so we need to create proper VS Code objects here. | ||
const strings: vscode.MarkdownString[] = []; | ||
for (const element of hoverResult.contents) { | ||
const oldMarkdownString: vscode.MarkdownString = element as vscode.MarkdownString; | ||
const newMarkdownString: vscode.MarkdownString = new vscode.MarkdownString(oldMarkdownString.value, oldMarkdownString.supportThemeIcons); | ||
newMarkdownString.isTrusted = oldMarkdownString.isTrusted; | ||
newMarkdownString.supportHtml = oldMarkdownString.supportHtml; | ||
newMarkdownString.baseUri = oldMarkdownString.baseUri; | ||
strings.push(newMarkdownString); | ||
} | ||
let range: vscode.Range | undefined; | ||
if (hoverResult.range) { | ||
range = new vscode.Range(hoverResult.range.start.line, hoverResult.range.start.character, | ||
hoverResult.range.end.line, hoverResult.range.end.character); | ||
} | ||
|
||
return new vscode.Hover(strings, range); | ||
} | ||
} |
This file contains 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.