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

WIP: Dataflow #40

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
33 changes: 33 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
"name": "Inheritance Hierarchy",
"when": "extension.ccls.inheritanceHierarchyVisible"
},
{
"id": "ccls.dataFlowInto",
"name": "Data Flow Hierarchy",
"when": "extension.ccls.dataFlowHierarchyVisible"
},
{
"id": "ccls.memberHierarchy",
"name": "Member Hierarchy",
Expand Down Expand Up @@ -89,6 +94,11 @@
"command": "ccls.base",
"when": "resourceLangId == cpp",
"group": "[email protected]"
},
{
"command": "ccls.dataFlowInto",
"when": "resourceLangId == cpp",
"group": "[email protected]"
}
],
"view/title": [
Expand All @@ -107,6 +117,11 @@
"when": "view == ccls.callHierarchy",
"group": "navigation"
},
{
"command": "ccls.closeDataFlowHierarchy",
"when": "view == ccls.dataFlowInto",
"group": "navigation"
},
{
"command": "ccls.closeInheritanceHierarchy",
"when": "view == ccls.inheritanceHierarchy",
Expand Down Expand Up @@ -137,6 +152,10 @@
"command": "ccls.closeMemberHierarchy",
"when": "false"
},
{
"command": "ccls.closeDataFlowHierarchy",
"when": "false"
},
{
"command": "ccls.gotoForTreeView",
"when": "false"
Expand Down Expand Up @@ -229,6 +248,20 @@
"category": "ccls",
"command": "ccls.vars"
},
{
"title": "Show Data Flow Into",
"category": "ccls",
"command": "ccls.dataFlowInto"
},
{
"title": "Close",
"category": "ccls",
"command": "ccls.closeDataFlowHierarchy",
"icon": {
"light": "resources/close-light.svg",
"dark": "resources/close-dark.svg"
}
},
{
"title": "Show Cross References",
"category": "ccls",
Expand Down
70 changes: 70 additions & 0 deletions src/hierarchies/dataFlowHierarchy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import {
commands,
Disposable,
Event,
EventEmitter,
Position,
Range,
TextEditor,
TreeDataProvider,
TreeItem,
TreeItemCollapsibleState,
Uri,
workspace
} from "vscode";
import { LanguageClient } from "vscode-languageclient/lib/main";
import { Icon, IHierarchyNode } from "../types";
import { disposeAll, resourcePath, setContext } from "../utils";
import { Hierarchy } from "./hierarchy";

interface DataFlowHierarchyNode extends IHierarchyNode {
children: DataFlowHierarchyNode[];
}

export class DataFlowHierarchyProvider extends Hierarchy<DataFlowHierarchyNode> {
protected contextValue = 'extension.ccls.dataFlowHierarchyVisible';
private icon: Icon;

constructor(
readonly languageClient: LanguageClient,
) {
super(languageClient, 'ccls.dataFlowInto', 'ccls.closeDataFlowHierarchy');
this.icon = {
dark: resourcePath("base-dark.svg"),
light: resourcePath("base-light.svg")
};
}

protected async onTreeItem(ti: TreeItem, element: DataFlowHierarchyNode) {

const parentFile = await workspace.openTextDocument(Uri.parse(element.location.uri));
ti.label = parentFile.getText(
new Range(
new Position(element.location.range.start.line, element.location.range.start.character),
new Position(element.location.range.end.line, element.location.range.end.character)
)
);

ti.iconPath = this.icon;
ti.contextValue = 'cclsGoto';

}

protected async onGetChildren(
element: DataFlowHierarchyNode
): Promise<DataFlowHierarchyNode[]> {
return element.children;
}

protected async onReveal(uri: Uri, position: Position): Promise<DataFlowHierarchyNode> {
return this.languageClient.sendRequest<DataFlowHierarchyNode>(
'$ccls/dataFlowInto',
{
position,
textDocument: {
uri: uri.toString(true),
},
}
);
}
}
7 changes: 7 additions & 0 deletions src/serverContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import * as ls from "vscode-languageserver-types";
import { CclsErrorHandler } from "./cclsErrorHandler";
import { cclsChan, logChan } from './globalContext';
import { CallHierarchyProvider } from "./hierarchies/callHierarchy";
import { DataFlowHierarchyProvider } from "./hierarchies/dataFlowHierarchy";
import { InheritanceHierarchyProvider } from "./hierarchies/inheritanceHierarchy";
import { MemberHierarchyProvider } from "./hierarchies/memberHierarchy";
import { InactiveRegionsProvider } from "./inactiveRegions";
Expand Down Expand Up @@ -262,6 +263,12 @@ export class ServerContext implements Disposable {
'ccls.memberHierarchy', memberHierarchyProvider
));

const dfProvier = new DataFlowHierarchyProvider(this.client);
this._dispose.push(dfProvier);
this._dispose.push(window.registerTreeDataProvider(
'ccls.dataFlowInto', dfProvier
));

// Common between tree views.
this._dispose.push(commands.registerCommand(
"ccls.gotoForTreeView", this.gotoForTreeView, this
Expand Down