Skip to content

Commit

Permalink
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 <[email protected]>
  • Loading branch information
vince-fugnitto committed Jul 9, 2021
1 parent 8e9ce81 commit 346d103
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 2 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
Expand Up @@ -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
};
}

Expand Down
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
Expand Up @@ -219,6 +219,7 @@ export enum MarkerSeverity {

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

export interface ParameterInformation {
Expand Down
14 changes: 14 additions & 0 deletions packages/plugin-ext/src/main/browser/languages-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -955,6 +960,15 @@ function reviveRelated(related: RelatedInformation): vst.DiagnosticRelatedInform
};
}

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

function reviveRegExp(regExp?: SerializedRegExp): RegExp | undefined {
if (typeof regExp === 'undefined' || regExp === null) {
return undefined;
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-ext/src/plugin/languages/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-ext/src/plugin/type-converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ function convertTags(tags: types.DiagnosticTag[] | undefined): types.MarkerTag[]
for (const tag of tags) {
switch (tag) {
case types.DiagnosticTag.Unnecessary: markerTags.push(types.MarkerTag.Unnecessary);
case types.DiagnosticTag.Deprecated: markerTags.push(types.MarkerTag.Deprecated);
}
}
return markerTags;
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-ext/src/plugin/types-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,7 @@ export class Location {

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

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

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

export class ParameterInformation {
Expand Down
6 changes: 6 additions & 0 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

/**
Expand Down

0 comments on commit 346d103

Please sign in to comment.