diff --git a/packages/plugin-ext/src/plugin/type-converters.spec.ts b/packages/plugin-ext/src/plugin/type-converters.spec.ts index a76b3de3fa7f2..2130d6e342cc5 100644 --- a/packages/plugin-ext/src/plugin/type-converters.spec.ts +++ b/packages/plugin-ext/src/plugin/type-converters.spec.ts @@ -437,4 +437,24 @@ describe('Type converters:', () => { assert.deepStrictEqual(result, showOptions); }); }); + + describe('#convertCode', () => { + it('should convert a "code" of type "string"', () => { + assert.strictEqual(Converter.convertCode('string'), 'string'); + }); + it('should convert a "code" of type "number"', () => { + assert.strictEqual(Converter.convertCode(4), '4'); + }); + it('should convert an undefined "code"', () => { + assert.strictEqual(Converter.convertCode(undefined), undefined); + }); + it('should convert a "code" of type "{ value: number, target: Uri }"', () => { + const uri = types.URI.parse('foo://example.com:8042/over/there?name=ferret#nose'); + assert.strictEqual(Converter.convertCode({ value: 4, target: uri }), '4'); + }); + it('should convert a "code" of type "{ value: number, target: Uri }"', () => { + const uri = types.URI.parse('foo://example.com:8042/over/there?name=ferret#nose'); + assert.strictEqual(Converter.convertCode({ value: 'string', target: uri }), 'string'); + }); + }); }); diff --git a/packages/plugin-ext/src/plugin/type-converters.ts b/packages/plugin-ext/src/plugin/type-converters.ts index 4b80b2b11a2f9..116ec4fbb959b 100644 --- a/packages/plugin-ext/src/plugin/type-converters.ts +++ b/packages/plugin-ext/src/plugin/type-converters.ts @@ -332,12 +332,15 @@ export function convertDiagnosticToMarkerData(diagnostic: theia.Diagnostic): mod }; } -function convertCode(code: string | number | undefined): string | undefined { +export function convertCode(code: string | number | { value: string | number; target: theia.Uri } | undefined): string | undefined { if (typeof code === 'number') { return String(code); - } else { - return code; } + if (typeof code === 'string' || typeof code === 'undefined') { + return code; + } else { + return String(code.value); + }; } function convertSeverity(severity: types.DiagnosticSeverity): types.MarkerSeverity { diff --git a/packages/plugin/src/theia.d.ts b/packages/plugin/src/theia.d.ts index e40bce79c6793..725d19f0c95c7 100644 --- a/packages/plugin/src/theia.d.ts +++ b/packages/plugin/src/theia.d.ts @@ -8233,11 +8233,21 @@ export module '@theia/plugin' { source?: string; /** - * A code or identifier for this diagnostics. Will not be surfaced - * to the user, but should be used for later processing, e.g. when - * providing {@link CodeActionContext code actions}. + * A code or identifier for this diagnostic. + * Should be used for later processing, e.g. when providing {@link CodeActionContext code actions}. */ - code?: string | number; + code?: string | number | { + /** + * A code or identifier for this diagnostic. + * Should be used for later processing, e.g. when providing {@link CodeActionContext code actions}. + */ + value: string | number; + + /** + * A target URI to open with more information about the diagnostic error. + */ + target: Uri; + }; /** * An array of related diagnostic information, e.g. when symbol-names within