Skip to content

Commit

Permalink
Add full support for Diagnostic.code
Browse files Browse the repository at this point in the history
  • Loading branch information
Estelle Foisy committed Sep 27, 2022
1 parent 15894d8 commit 35a4c2d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
21 changes: 21 additions & 0 deletions packages/plugin-ext/src/plugin/type-converters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { MarkdownString } from './markdown-string';
import { MarkdownString as MarkdownStringInterface } from '@theia/core/lib/common/markdown-rendering';
import { TaskDto } from '../common/plugin-api-rpc';
import { TaskGroup } from './types-impl';
import { expect } from 'chai';

describe('Type converters:', () => {

Expand Down Expand Up @@ -437,4 +438,24 @@ describe('Type converters:', () => {
assert.deepStrictEqual(result, showOptions);
});
});

describe.only('#convertCode', () => {
it('should return "true" if convertCode(string) is of string type (string)', () => {
expect(Converter.convertCode('string')).to.equal('string');
});
it('should return "true" if convertCode(4) of string type (4)', () => {
expect(Converter.convertCode(4)).to.equal('4');
});
it('should return "true" if convertCode is undefined', () => {
expect(Converter.convertCode(undefined)).to.equal(undefined);
});
it('should return "true" if convertcode(object) is of string type (4)', () => {
const UriCode = types.URI.parse('foo://example.com:8042/over/there?name=ferret#nose');
expect(Converter.convertCode({ value: 4, target: UriCode })).to.equal('4');
});
it('should return "true" if convertcode(object) is of string type (string)', () => {
const UriCode = types.URI.parse('foo://example.com:8042/over/there?name=ferret#nose');
expect(Converter.convertCode({ value: 'string', target: UriCode })).to.equal('string');
});
});
});
10 changes: 7 additions & 3 deletions packages/plugin-ext/src/plugin/type-converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,16 @@ 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 code = String(code.value);
};
}

function convertSeverity(severity: types.DiagnosticSeverity): types.MarkerSeverity {
Expand Down
18 changes: 14 additions & 4 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8186,11 +8186,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
Expand Down

0 comments on commit 35a4c2d

Please sign in to comment.