Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add full support for Diagnostic.code #11765

Merged
merged 1 commit into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Copy link
Contributor

@colin-grant-work colin-grant-work Oct 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there's loss of information here. Is there a reason we don't want to include the target field in the code when we convert it? I notice that the corresponding code in VSCode does preserve the target:

https://github.com/microsoft/vscode/blob/65a9097aa2da4d55318073ca23bc678a2885c461/src/vs/workbench/api/common/extHostTypeConverters.ts#L198-L207

Though when they're reconstructing a Diagonstic from the DTO, they ignore the target. Not very clear (to me) why.

https://github.com/microsoft/vscode/blob/65a9097aa2da4d55318073ca23bc678a2885c461/src/vs/workbench/api/common/extHostTypeConverters.ts#L223

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@colin-grant-work I believe it was done this way due to the conversion of vst.Diagnostic (vscode-languageserver-types) which did not support the new type:

function reviveMarker(marker: MarkerData): vst.Diagnostic {
const monacoMarker: vst.Diagnostic = {
code: marker.code,
severity: reviveSeverity(marker.severity),
range: reviveRange(marker.startLineNumber, marker.startColumn, marker.endLineNumber, marker.endColumn),
message: marker.message,
source: marker.source,
relatedInformation: undefined
};

/**
 * Represents a diagnostic, such as a compiler error or warning. Diagnostic objects
 * are only valid in the scope of a resource.
 */
export interface Diagnostic {
    /**
     * The range at which the message applies
     */
    range: Range;
    /**
     * The diagnostic's severity. Can be omitted. If omitted it is up to the
     * client to interpret diagnostics as error, warning, info or hint.
     */
    severity?: DiagnosticSeverity;
    /**
     * The diagnostic's code, which usually appear in the user interface.
     */
    code?: number | string;
    /**
     * A human-readable string describing the source of this
     * diagnostic, e.g. 'typescript' or 'super lint'. It usually
     * appears in the user interface.
     */
    source?: string;
    /**
     * The diagnostic's message. It usually appears in the user interface
     */
    message: string;
    /**
     * Additional metadata about the diagnostic.
     */
    tags?: DiagnosticTag[];
    /**
     * An array of related diagnostic information, e.g. when symbol-names within
     * a scope collide all definitions can be marked via this property.
     */
    relatedInformation?: DiagnosticRelatedInformation[];
}

We could from the types-converter convert fully, and only when it comes time to reviveMarker we update to ensure the types match.

});
});
});
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