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 Oct 13, 2022
1 parent 32739c4 commit 53315a0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
20 changes: 20 additions & 0 deletions packages/plugin-ext/src/plugin/type-converters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
9 changes: 6 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,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 {
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 @@ -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
Expand Down

0 comments on commit 53315a0

Please sign in to comment.