Skip to content

Commit 2ad3d18

Browse files
committed
[Statistic] Do not show statistics, switch focus according to a request.
1 parent a311bb7 commit 2ad3d18

File tree

7 files changed

+29
-8
lines changed

7 files changed

+29
-8
lines changed

src/aliasTree.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function registerCommands(engine: ProjectEngine, subscriptions: Disposabl
1616
let project = engine.project(uri);
1717
let state = project.providerState(AliasTreeProvider.scheme);
1818
state.active = true;
19+
project.focus = state;
1920
let request = new msg.AliasTree;
2021
let query = JSON.parse(uri.query);
2122
request.FuncID = query.FuncID;

src/extension.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,10 @@ export function activate(context: vscode.ExtensionContext) {
8383
})
8484
.then(
8585
async project => {
86-
let state = project.providerState(ProjectProvider.scheme);
87-
state.onDidDisposeContent(() => {engine.stop(project)},
88-
null, context.subscriptions);
8986
await engine.runTool(project);
9087
project.providerState(FileListProvider.scheme).active = true;
9188
project.send(new msg.FileList);
92-
state.active = true;
93-
project.send(new msg.Statistic);
89+
vscode.commands.executeCommand('tsar.function.list', project.uri);
9490
},
9591
reason => { onReject(reason, uri) })
9692
});
@@ -180,6 +176,7 @@ export function activate(context: vscode.ExtensionContext) {
180176
// Dispose current webview if required request is new.
181177
state.active = false;
182178
state.active = true;
179+
project.focus = state;
183180
project.send(request);
184181
});
185182
context.subscriptions.push(start, stop, openProject, showCalleeFunc);

src/fileList.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export class FileListProvider implements ProjectContentProvider {
170170
});
171171
});
172172
}
173+
clear(project: Project): any {}
173174
dispose() {
174175
this._disposables.forEach(d => d.dispose());
175176
this._disposables.length = 0;

src/loopTree.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export function registerCommands(engine: ProjectEngine, subscriptions: Disposabl
2525
let project = engine.project(uri);
2626
let state = project.providerState(LoopTreeProvider.scheme);
2727
state.active = true;
28+
project.focus = state;
2829
let request = new msg.FunctionList;
2930
if (!state.actual(request))
3031
project.send(request);
@@ -34,6 +35,7 @@ export function registerCommands(engine: ProjectEngine, subscriptions: Disposabl
3435
let project = engine.project(uri);
3536
let state = project.providerState(LoopTreeProvider.scheme);
3637
state.active = true;
38+
project.focus = state;
3739
let looptree = new msg.LoopTree;
3840
let query = JSON.parse(uri.query);
3941
looptree.FunctionID = query.ID;
@@ -120,6 +122,9 @@ export class LoopTreeProvider extends ProjectWebviewProvider {
120122
return new LoopTreeProviderState(this);
121123
}
122124

125+
clear(project: Project) {
126+
}
127+
123128
protected _title(): string { return log.FunctionList.title; }
124129

125130
protected _needToHandle(response: any): boolean {

src/project.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,11 @@ export interface ProjectContentProvider {
521521
*/
522522
update(project: Project): any;
523523

524+
/**
525+
* Clear visible content for a specified project.
526+
*/
527+
clear(project: Project): any;
528+
524529
/**
525530
* Dispose provider.
526531
*/
@@ -605,6 +610,8 @@ export class Project {
605610

606611
public arguments: msg.Arguments;
607612

613+
public focus: ProjectContentProviderState;
614+
608615
/**
609616
* Create a project with a specified uri.
610617
*
@@ -637,6 +644,7 @@ export class Project {
637644
dispose() {
638645
if (this._isDisposed)
639646
return;
647+
this._providers.forEach(state => {state.provider.clear(this)});
640648
this._isDisposed = true;
641649
this._providers.clear();
642650
this._output.hide();

src/transformProvider.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export function registerCommands(
5151
});
5252
}).then((value) => {vscode.commands.executeCommand('tsar.stop', project.uri)});
5353
state.active = true;
54+
project.focus = state;
5455
await engine.runTool(project, info.run)
5556
project.send('');
5657
},
@@ -96,6 +97,7 @@ export class TransformationProvider implements ProjectContentProvider {
9697
readonly onDidAriseInternalError = this._onDidAriseInternalError.event;
9798

9899
state(): TransformationProviderState { return new TransformationProviderState(this) };
100+
clear() {}
99101

100102
update(project: Project) {
101103
let state = project.providerState(

src/webviewProvider.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,18 @@ export class ProjectWebviewProviderState<ProviderT extends ProjectWebviewProvide
8181
this._panel = vscode.window.createWebviewPanel(
8282
this._provider.scheme(),
8383
log.Extension.displayName,
84-
columnToShowIn,
84+
{
85+
viewColumn: columnToShowIn,
86+
preserveFocus: true,
87+
},
8588
{
8689
enableCommandUris: true,
8790
enableScripts: true,
8891
enableFindWidget: true,
8992
}
9093
);
9194
this._panel.onDidDispose(() => {
95+
this.active = false;
9296
this._hasPanel = false;
9397
this._onDidDisposeContent.fire();
9498
}, null, this.disposables);
@@ -106,12 +110,14 @@ export class ProjectWebviewProviderState<ProviderT extends ProjectWebviewProvide
106110
}
107111

108112
export abstract class ProjectWebviewProvider implements ProjectContentProvider{
109-
protected readonly _disposables: vscode.Disposable[];
113+
protected readonly _disposables: vscode.Disposable[] = [];
110114

111115
protected _onDidAriseInternalError = new vscode.EventEmitter<Error>();
112116
readonly onDidAriseInternalError = this._onDidAriseInternalError.event;
113117

114118
dispose() { this._disposables.forEach(d => d.dispose()); }
119+
clear(project: Project) {}
120+
115121

116122
/**
117123
* Return a new description of a project content provider state.
@@ -133,7 +139,8 @@ export abstract class ProjectWebviewProvider implements ProjectContentProvider{
133139
let panel = state.panel;
134140
panel.title = `${log.Extension.displayName} | ${project.prjname}`;
135141
panel.webview.html = data;
136-
panel.reveal();
142+
if (project.focus == state)
143+
panel.reveal();
137144
}, data => {
138145
this._onDidAriseInternalError.fire(new Error(data));
139146
vscode.window.showErrorMessage(log.Extension.displayName +

0 commit comments

Comments
 (0)