Skip to content

Commit e6d6019

Browse files
feat: getDefination
1 parent cd02f1e commit e6d6019

2 files changed

Lines changed: 44 additions & 12 deletions

File tree

package-lock.json

Lines changed: 11 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/lspClient.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ export default class lspClient {
9191
* Add an editor to the language provider
9292
* @param {Object} editor - Ace editor instance
9393
* @returns {boolean} - Success status
94+
*
95+
* Note: this is not limited to a single editor tab
9496
*/
9597
addEditor(editor) {
9698
if (!editor) {
@@ -295,6 +297,36 @@ export default class lspClient {
295297
return new Set(this.registeredEditors);
296298
}
297299

300+
async sendRequest(method, params) {
301+
return new Promise((resolve, reject) => {
302+
try {
303+
this.languageProvider.sendRequest(
304+
"lspClient",
305+
method,
306+
params,
307+
(result) => {
308+
resolve(result);
309+
}
310+
);
311+
} catch (err) {
312+
reject(err);
313+
}
314+
});
315+
}
316+
317+
async getDefination(editor, uri) {
318+
const result = await this.sendRequest("textDocument/definition", {
319+
textDocument: { uri },
320+
position: {
321+
line: editor.getCursorPosition().row,
322+
character: editor.getCursorPosition().column,
323+
},
324+
});
325+
326+
return result;
327+
}
328+
329+
298330
// Private helper methods
299331

300332
/**
@@ -307,6 +339,7 @@ export default class lspClient {
307339
modes: this.modes,
308340
type: "socket",
309341
socket: this.socket,
342+
serviceName: "lspClient",
310343
initializationOptions: this.initializationOptions,
311344
};
312345

0 commit comments

Comments
 (0)