Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugin: add showDeprecated support
Browse files Browse the repository at this point in the history
The commit adds support for the `showDeprecated` monaco editor option
which is contributed by language-servers to display deprecated
strike-throughs in code which is deprecated.

Signed-off-by: vince-fugnitto <vincent.fugnitto@ericsson.com>
vince-fugnitto committed Jul 9, 2021

Verified

This commit was signed with the committer’s verified signature. The key has expired.
zakkak Foivos Zakkak
1 parent 8e9ce81 commit 46421ec
Showing 7 changed files with 31 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/monaco/src/browser/protocol-to-monaco-converter.ts
Original file line number Diff line number Diff line change
@@ -131,7 +131,8 @@ export class ProtocolToMonacoConverter {
startColumn: diagnostic.range.start.character + 1,
endLineNumber: diagnostic.range.end.line + 1,
endColumn: diagnostic.range.end.character + 1,
relatedInformation: this.asRelatedInformations(diagnostic.relatedInformation)
relatedInformation: this.asRelatedInformations(diagnostic.relatedInformation),
tags: diagnostic.tags
};
}

1 change: 1 addition & 0 deletions packages/plugin-ext/src/common/plugin-api-rpc-model.ts
Original file line number Diff line number Diff line change
@@ -219,6 +219,7 @@ export enum MarkerSeverity {

export enum MarkerTag {
Unnecessary = 1,
Deprecated = 2,
}

export interface ParameterInformation {
12 changes: 12 additions & 0 deletions packages/plugin-ext/src/main/browser/languages-main.ts
Original file line number Diff line number Diff line change
@@ -57,6 +57,7 @@ import { ObjectIdentifier } from '../../common/object-identifier';
import { mixin } from '../../common/types';
import { relative } from '../../common/paths-util';
import { decodeSemanticTokensDto } from '../../common/semantic-tokens-dto';
import { DiagnosticTag } from '@theia/core/shared/vscode-languageserver-protocol';

@injectable()
export class LanguagesMainImpl implements LanguagesMain, Disposable {
@@ -919,6 +920,10 @@ function reviveMarker(marker: MarkerData): vst.Diagnostic {
monacoMarker.relatedInformation = marker.relatedInformation.map(reviveRelated);
}

if (marker.tags) {
monacoMarker.tags = marker.tags.map(reviveTag);
}

return monacoMarker;
}

@@ -955,6 +960,13 @@ function reviveRelated(related: RelatedInformation): vst.DiagnosticRelatedInform
};
}

function reviveTag(tag: DiagnosticTag): vst.DiagnosticTag {
switch (tag) {
case 1: return DiagnosticTag.Unnecessary;
case 2: return DiagnosticTag.Deprecated;
}
}

function reviveRegExp(regExp?: SerializedRegExp): RegExp | undefined {
if (typeof regExp === 'undefined' || regExp === null) {
return undefined;
3 changes: 2 additions & 1 deletion packages/plugin-ext/src/plugin/languages/diagnostics.ts
Original file line number Diff line number Diff line change
@@ -223,7 +223,8 @@ export class DiagnosticCollection implements theia.DiagnosticCollection {
startLineNumber: lastMarker.startLineNumber,
startColumn: lastMarker.startColumn,
endLineNumber: lastMarker.endLineNumber,
endColumn: lastMarker.endColumn
endColumn: lastMarker.endColumn,
tags: lastMarker.tags,
});
markers.push([uri.toString(), uriMarkers]);
continue nextUri;
7 changes: 6 additions & 1 deletion packages/plugin-ext/src/plugin/type-converters.ts
Original file line number Diff line number Diff line change
@@ -376,7 +376,12 @@ function convertTags(tags: types.DiagnosticTag[] | undefined): types.MarkerTag[]
const markerTags: types.MarkerTag[] = [];
for (const tag of tags) {
switch (tag) {
case types.DiagnosticTag.Unnecessary: markerTags.push(types.MarkerTag.Unnecessary);
case types.DiagnosticTag.Unnecessary:
markerTags.push(types.MarkerTag.Unnecessary);
break;
case types.DiagnosticTag.Deprecated:
markerTags.push(types.MarkerTag.Deprecated);
break;
}
}
return markerTags;
2 changes: 2 additions & 0 deletions packages/plugin-ext/src/plugin/types-impl.ts
Original file line number Diff line number Diff line change
@@ -944,6 +944,7 @@ export class Location {

export enum DiagnosticTag {
Unnecessary = 1,
Deprecated = 2,
}

export enum CompletionItemTag {
@@ -975,6 +976,7 @@ export enum MarkerSeverity {

export enum MarkerTag {
Unnecessary = 1,
Deprecated = 2,
}

export class ParameterInformation {
6 changes: 6 additions & 0 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
@@ -7332,6 +7332,12 @@ declare module '@theia/plugin' {
* instead of fading it out.
*/
Unnecessary = 1,
/**
* Deprecated or obsolete code.
*
* Diagnostics with this tag are rendered with a strike through.
*/
Deprecated = 2,
}

/**

0 comments on commit 46421ec

Please sign in to comment.