Skip to content

Commit 9419f57

Browse files
authored
feat: add getPreferredUILocation request for other tooling (#2075)
1 parent f7a1450 commit 9419f57

File tree

5 files changed

+366
-181
lines changed

5 files changed

+366
-181
lines changed

dprint.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"**/node_modules",
1414
"**/testWorkspace",
1515
"**/*-lock.json",
16-
"**/*.d.ts"
16+
"**/*.d.ts",
17+
"!src/{dap,cdp}/*.d.ts"
1718
],
1819
"plugins": [
1920
"https://plugins.dprint.dev/typescript-0.91.6.wasm",

src/adapter/debugAdapter.ts

+25
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,31 @@ export class DebugAdapter implements IDisposable {
126126
this.dap.on('setSymbolOptions', params => this._setSymbolOptions(params));
127127
this.dap.on('networkCall', params => this._doNetworkCall(params));
128128
this.dap.on('enableNetworking', params => this._withThread(t => t.enableNetworking(params)));
129+
this.dap.on(
130+
'getPreferredUILocation',
131+
params => this._getPreferredUILocation(params),
132+
);
133+
}
134+
135+
private async _getPreferredUILocation(
136+
params: Dap.GetPreferredUILocationParams,
137+
): Promise<Dap.GetPreferredUILocationResult> {
138+
const source = this.sourceContainer.source(params.source);
139+
if (!source) {
140+
return params;
141+
}
142+
143+
const location = await this.sourceContainer.preferredUiLocation({
144+
columnNumber: params.column + 1,
145+
lineNumber: params.line + 1,
146+
source,
147+
});
148+
149+
return {
150+
column: location.columnNumber - 1,
151+
line: location.lineNumber - 1,
152+
source: await location.source.toDap(),
153+
};
129154
}
130155

131156
private async _doNetworkCall({ method, params }: Dap.NetworkCallParams) {

src/build/dapCustom.ts

+39
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,45 @@ const dapCustom: JSONSchema4 = {
786786
type: 'object',
787787
},
788788
),
789+
790+
...makeRequest(
791+
'getPreferredUILocation',
792+
'Resolves a compiled location into a preferred source location. May be used by other VS Code extensions.',
793+
{
794+
properties: {
795+
source: {
796+
$ref: '#/definitions/Source',
797+
description: 'The source to look up.',
798+
},
799+
line: {
800+
type: 'integer',
801+
description: 'The base-0 line number to look up.',
802+
},
803+
column: {
804+
type: 'integer',
805+
description: 'The base-0 column number to look up.',
806+
},
807+
},
808+
required: ['source', 'line', 'column'],
809+
},
810+
{
811+
properties: {
812+
source: {
813+
$ref: '#/definitions/Source',
814+
description: 'The resolved source.',
815+
},
816+
line: {
817+
type: 'integer',
818+
description: 'The base-0 line number in the source.',
819+
},
820+
column: {
821+
type: 'integer',
822+
description: 'The base-0 column number in the source.',
823+
},
824+
},
825+
required: ['source', 'line', 'column'],
826+
},
827+
),
789828
},
790829
};
791830

0 commit comments

Comments
 (0)