Skip to content

Commit

Permalink
feat: add getPreferredUILocation request for other tooling (#2075)
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 authored Sep 5, 2024
1 parent f7a1450 commit 9419f57
Show file tree
Hide file tree
Showing 5 changed files with 366 additions and 181 deletions.
3 changes: 2 additions & 1 deletion dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"**/node_modules",
"**/testWorkspace",
"**/*-lock.json",
"**/*.d.ts"
"**/*.d.ts",
"!src/{dap,cdp}/*.d.ts"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.91.6.wasm",
Expand Down
25 changes: 25 additions & 0 deletions src/adapter/debugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,31 @@ export class DebugAdapter implements IDisposable {
this.dap.on('setSymbolOptions', params => this._setSymbolOptions(params));
this.dap.on('networkCall', params => this._doNetworkCall(params));
this.dap.on('enableNetworking', params => this._withThread(t => t.enableNetworking(params)));
this.dap.on(
'getPreferredUILocation',
params => this._getPreferredUILocation(params),
);
}

private async _getPreferredUILocation(
params: Dap.GetPreferredUILocationParams,
): Promise<Dap.GetPreferredUILocationResult> {
const source = this.sourceContainer.source(params.source);
if (!source) {
return params;
}

const location = await this.sourceContainer.preferredUiLocation({
columnNumber: params.column + 1,
lineNumber: params.line + 1,
source,
});

return {
column: location.columnNumber - 1,
line: location.lineNumber - 1,
source: await location.source.toDap(),
};
}

private async _doNetworkCall({ method, params }: Dap.NetworkCallParams) {
Expand Down
39 changes: 39 additions & 0 deletions src/build/dapCustom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,45 @@ const dapCustom: JSONSchema4 = {
type: 'object',
},
),

...makeRequest(
'getPreferredUILocation',
'Resolves a compiled location into a preferred source location. May be used by other VS Code extensions.',
{
properties: {
source: {
$ref: '#/definitions/Source',
description: 'The source to look up.',
},
line: {
type: 'integer',
description: 'The base-0 line number to look up.',
},
column: {
type: 'integer',
description: 'The base-0 column number to look up.',
},
},
required: ['source', 'line', 'column'],
},
{
properties: {
source: {
$ref: '#/definitions/Source',
description: 'The resolved source.',
},
line: {
type: 'integer',
description: 'The base-0 line number in the source.',
},
column: {
type: 'integer',
description: 'The base-0 column number in the source.',
},
},
required: ['source', 'line', 'column'],
},
),
},
};

Expand Down
Loading

0 comments on commit 9419f57

Please sign in to comment.