Skip to content

Commit

Permalink
Send document buffer when semantically highlighting old document vers…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
JoeRobich committed Dec 17, 2021
1 parent fc0c720 commit 9b6f3a7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* Use 6.0.100 SDK for building (PR: [omnisharp-roslyn#2269](https://github.com/OmniSharp/omnisharp-roslyn/pull/2269))
* Added Code of Conduct (PR: [omnisharp-roslyn#2266](https://github.com/OmniSharp/omnisharp-roslyn/pull/2266))
* Improved Cake/CSX info messages (PR: [omnisharp-roslyn#2264](https://github.com/OmniSharp/omnisharp-roslyn/pull/2264))
* Send document buffer when semantically highlighting old document versions (PR: [#4915](https://github.com/OmniSharp/omnisharp-vscode/pull/4915))
* Improved Regex syntax highlighting (PR: [#4902](https://github.com/OmniSharp/omnisharp-vscode/pull/4902))
* .NET 6 bug fixes ([#4931](https://github.com/OmniSharp/omnisharp-vscode/issues/4931), PR: [#4950](https://github.com/OmniSharp/omnisharp-vscode/pull/4950))
* Add File-scoped namespace snippet (PR: [#4948](https://github.com/OmniSharp/omnisharp-vscode/pull/4948))
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ You can also use the .NET 6 build of OmniSharp which runs on the .NET 6 SDK. See
* Use 6.0.100 SDK for building (PR: [omnisharp-roslyn#2269](https://github.com/OmniSharp/omnisharp-roslyn/pull/2269))
* Added Code of Conduct (PR: [omnisharp-roslyn#2266](https://github.com/OmniSharp/omnisharp-roslyn/pull/2266))
* Improved Cake/CSX info messages (PR: [omnisharp-roslyn#2264](https://github.com/OmniSharp/omnisharp-roslyn/pull/2264))
* Send document buffer when semantically highlighting old document versions (PR: [#4915](https://github.com/OmniSharp/omnisharp-vscode/pull/4915))
* Improved Regex syntax highlighting (PR: [#4902](https://github.com/OmniSharp/omnisharp-vscode/pull/4902))
* .NET 6 bug fixes ([#4931](https://github.com/OmniSharp/omnisharp-vscode/issues/4931), PR: [#4950](https://github.com/OmniSharp/omnisharp-vscode/pull/4950))
* Add File-scoped namespace snippet (PR: [#4948](https://github.com/OmniSharp/omnisharp-vscode/pull/4948))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@
},
"csharp.semanticHighlighting.enabled": {
"type": "boolean",
"default": false,
"default": true,
"description": "Enable/disable Semantic Highlighting for C# files (Razor files currently unsupported). Defaults to false. Close open files for changes to take effect.",
"scope": "window"
},
Expand Down
8 changes: 8 additions & 0 deletions src/features/semanticTokensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ export default class SemanticTokensProvider extends AbstractProvider implements
let req = createRequest<protocol.V2.SemanticHighlightRequest>(document, new vscode.Position(0, 0));
req.Range = range;


// We need to include the document contents in our request when we are highlighting a version of the document other than the current version, such as in the Diff view.
const currentDocument = vscode.workspace.textDocuments.find(d => d.fileName === document.fileName);
const isCurrentVersion = currentDocument?.version === document.version;
if (!isCurrentVersion) {
req.VersionedText = document.getText();
}

const versionBeforeRequest = document.version;

const response = await serverUtils.getSemanticHighlights(this._server, req);
Expand Down
1 change: 1 addition & 0 deletions src/omnisharp/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ export namespace V2 {

export interface SemanticHighlightRequest extends Request {
Range?: Range;
VersionedText?: string;
}

export interface SemanticHighlightResponse {
Expand Down

0 comments on commit 9b6f3a7

Please sign in to comment.