Comments (1)
Hi, me again 😄
In the meantime I found a way (not sure if it's the best) using an extension and the following commands from https://code.visualstudio.com/api/references/commands:
vscode.prepareCallHierarchy
- Prepare call hierarchy at a position inside a document
- uri - Uri of a text document
- position - A position in a text document
- (returns) - A promise that resolves to an array of CallHierarchyItem-instances
vscode.provideIncomingCalls
- Compute incoming calls for an item
- item - A call hierarchy item
- (returns) - A promise that resolves to an array of CallHierarchyIncomingCall-instances
vscode.provideOutgoingCalls
- Compute outgoing calls for an item
- item - A call hierarchy item
- (returns) - A promise that resolves to an array of CallHierarchyOutgoingCall-instances
A working snippet (maybe it helps others).
import * as vscode from 'vscode';
async function logOutgoingCalls(item: vscode.CallHierarchyItem) {
const outgoingCalls: vscode.CallHierarchyOutgoingCall[] = await vscode.commands.executeCommand('vscode.provideOutgoingCalls', item);
// iterate over outgoingCalls
for (const outgoingCall of outgoingCalls) {
console.log(item.name, '-[:invokes]->', outgoingCall.to.name);
// recursively log outgoing calls
// TODO: handle cycles
await logOutgoingCalls(outgoingCall.to);
}
}
async function logIncomingCalls(item: vscode.CallHierarchyItem) {
const incomingCalls: vscode.CallHierarchyIncomingCall[] = await vscode.commands.executeCommand('vscode.provideIncomingCalls', item);
// iterate over incomingCalls
for (const incomingCall of incomingCalls) {
console.log(incomingCall.from.name, '-[:invokes]->', item.name);
// recursively log incoming calls
// TODO: handle cycles
await logIncomingCalls(incomingCall.from);
}
}
export function activate(context: vscode.ExtensionContext) {
console.log('Congratulations, your extension is now active!');
let disposable = vscode.commands.registerCommand('extension.logCallHierarchy', async () => {
if (vscode.window.activeTextEditor) {
const position = vscode.window.activeTextEditor.selection.active;
const uri = vscode.window.activeTextEditor.document.uri;
const items: vscode.CallHierarchyItem[] = await vscode.commands.executeCommand('vscode.prepareCallHierarchy', uri, position);
if (items) {
for (const item of items) {
// log incoming calls
console.log('Incoming calls of ', item.name);
await logIncomingCalls(item);
// log outgoing calls
console.log('Outgoing calls of ', item.name);
await logOutgoingCalls(item);
}
}
}
});
context.subscriptions.push(disposable);
let statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
statusBarItem.command = 'extension.logCallHierarchy';
statusBarItem.text = "Log Call Hierarchy";
statusBarItem.show();
context.subscriptions.push(statusBarItem);
}
export function deactivate() { }
From my point of view this can be closed - thank you.
from vscode-languageserver-node.
Related Issues (20)
- Can you provide a monaco-editor demo HOT 2
- semanticTokensProvider is missing Connection implementation HOT 12
- Incorrect results about Go-to-definition and Go-to-declaration HOT 1
- Extra semanticTokens requests in a multiroot workspace HOT 1
- _WindowMiddleware - wrong definition for showDocument HOT 1
- Document links not rendering in editor despite being correctly returned from the language server
- Is `workspace/didChangeConfiguration` must be send on LSP client when server is initialized?
- Question about the order of LSP requests and notifications (didChange and semanticTokens) HOT 6
- Stopped client can recreate its OutputChannel HOT 1
- How to handle cancelled `window/showMessageRequest` HOT 2
- FileSystemWatcher and batching HOT 7
- Allow customizing the name of the option for enabling tracing HOT 1
- vscode-languageclient/lib/common/client.js' doesn't provide an export named: 'BaseLanguageClient'
- notebook event is broken. (re-ordering cells) HOT 2
- Expose JSON-RPC Error Code in communication with LSP Server HOT 1
- `textDocument/definition` does not work if cursor is inside `targetSelectionRange` HOT 2
- The order of Request(completion) and Notification(did_change) seems to changed HOT 4
- Error: spawn EINVAL when starting the Language Server HOT 9
- ERR_SOCKET_CLOSED_BEFORE_CONNECTION could not start Language Server HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vscode-languageserver-node.