Skip to content

Commit 83593d2

Browse files
authored
Merge pull request #971 from madushajg/bi-multi-project-auto-reveal
Re-enable auto-reveal in tree view based on the active webview
2 parents 95637e1 + c6058a5 commit 83593d2

File tree

4 files changed

+331
-73
lines changed

4 files changed

+331
-73
lines changed

workspaces/ballerina/ballerina-core/src/interfaces/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@ export const BI_COMMANDS = {
5353
ADD_NATURAL_FUNCTION: 'BI.project-explorer.add-natural-function',
5454
TOGGLE_TRACE_LOGS: 'BI.toggle.trace.logs',
5555
ADD_INTEGRATION: 'BI.project-explorer.add-integration',
56+
NOTIFY_PROJECT_EXPLORER: 'BI.project-explorer.notify',
5657
};

workspaces/ballerina/ballerina-extension/src/stateMachine.ts

Lines changed: 154 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,38 @@
22
import { ExtendedLangClient } from './core';
33
import { createMachine, assign, interpret } from 'xstate';
44
import { activateBallerina } from './extension';
5-
import { EVENT_TYPE, SyntaxTree, History, MachineStateValue, IUndoRedoManager, VisualizerLocation, webviewReady, MACHINE_VIEW, DIRECTORY_MAP, SCOPE, ProjectStructureResponse, ProjectStructureArtifactResponse, CodeData, ProjectDiagnosticsResponse, Type, dependencyPullProgress } from "@wso2/ballerina-core";
5+
import {
6+
EVENT_TYPE,
7+
SyntaxTree,
8+
History,
9+
MachineStateValue,
10+
IUndoRedoManager,
11+
VisualizerLocation,
12+
webviewReady,
13+
MACHINE_VIEW,
14+
DIRECTORY_MAP,
15+
SCOPE,
16+
ProjectStructureResponse,
17+
ProjectStructureArtifactResponse,
18+
CodeData,
19+
ProjectDiagnosticsResponse,
20+
Type,
21+
dependencyPullProgress,
22+
BI_COMMANDS,
23+
NodePosition
24+
} from "@wso2/ballerina-core";
625
import { fetchAndCacheLibraryData } from './features/library-browser';
726
import { VisualizerWebview } from './views/visualizer/webview';
827
import { commands, extensions, Uri, window, workspace, WorkspaceFolder } from 'vscode';
928
import { notifyCurrentWebview, RPCLayer } from './RPCLayer';
10-
import { generateUid, getComponentIdentifier, getNodeByIndex, getNodeByName, getNodeByUid, getView } from './utils/state-machine-utils';
29+
import {
30+
generateUid,
31+
getComponentIdentifier,
32+
getNodeByIndex,
33+
getNodeByName,
34+
getNodeByUid,
35+
getView
36+
} from './utils/state-machine-utils';
1137
import * as path from 'path';
1238
import { extension } from './BalExtensionContext';
1339
import { AIStateMachine } from './views/ai-panel/aiMachine';
@@ -89,6 +115,7 @@ const stateMachine = createMachine<MachineContext>(
89115
async (context, event) => {
90116
await buildProjectsStructure(context.projectInfo, StateMachine.langClient(), true);
91117
notifyCurrentWebview();
118+
notifyTreeView(event.projectPath, context.documentUri, context.position, context.view);
92119
// Resolve the next pending promise waiting for project root update completion
93120
pendingProjectRootUpdateResolvers.shift()?.();
94121
}
@@ -137,7 +164,13 @@ const stateMachine = createMachine<MachineContext>(
137164
position: (context, event) => event.viewLocation.position ? event.viewLocation.position : context.position,
138165
identifier: (context, event) => event.viewLocation.identifier ? event.viewLocation.identifier : context.identifier,
139166
addType: (context, event) => event.viewLocation?.addType !== undefined ? event.viewLocation.addType : context?.addType,
140-
})
167+
}),
168+
(context, event) => notifyTreeView(
169+
context.projectPath,
170+
event.viewLocation.documentUri || context.documentUri,
171+
event.viewLocation.position || context.position,
172+
context.view
173+
)
141174
]
142175
}
143176
},
@@ -149,26 +182,42 @@ const stateMachine = createMachine<MachineContext>(
149182
{
150183
target: "renderInitialView",
151184
cond: (context, event) => event.data && event.data.isBI,
152-
actions: assign({
153-
isBI: (context, event) => event.data.isBI,
154-
projectPath: (context, event) => event.data.projectPath,
155-
workspacePath: (context, event) => event.data.workspacePath,
156-
scope: (context, event) => event.data.scope,
157-
org: (context, event) => event.data.orgName,
158-
package: (context, event) => event.data.packageName
159-
})
185+
actions: [
186+
assign({
187+
isBI: (context, event) => event.data.isBI,
188+
projectPath: (context, event) => event.data.projectPath,
189+
workspacePath: (context, event) => event.data.workspacePath,
190+
scope: (context, event) => event.data.scope,
191+
org: (context, event) => event.data.orgName,
192+
package: (context, event) => event.data.packageName
193+
}),
194+
(context, event) => notifyTreeView(
195+
event.data.projectPath,
196+
context.documentUri,
197+
context.position,
198+
context.view
199+
)
200+
]
160201
},
161202
{
162203
target: "activateLS",
163204
cond: (context, event) => event.data && event.data.isBI === false,
164-
actions: assign({
165-
isBI: (context, event) => event.data.isBI,
166-
projectPath: (context, event) => event.data.projectPath,
167-
workspacePath: (context, event) => event.data.workspacePath,
168-
scope: (context, event) => event.data.scope,
169-
org: (context, event) => event.data.orgName,
170-
package: (context, event) => event.data.packageName
171-
})
205+
actions: [
206+
assign({
207+
isBI: (context, event) => event.data.isBI,
208+
projectPath: (context, event) => event.data.projectPath,
209+
workspacePath: (context, event) => event.data.workspacePath,
210+
scope: (context, event) => event.data.scope,
211+
org: (context, event) => event.data.orgName,
212+
package: (context, event) => event.data.packageName
213+
}),
214+
(context, event) => notifyTreeView(
215+
event.data.projectPath,
216+
context.documentUri,
217+
context.position,
218+
context.view
219+
)
220+
]
172221
}
173222
],
174223
onError: {
@@ -248,23 +297,31 @@ const stateMachine = createMachine<MachineContext>(
248297
on: {
249298
OPEN_VIEW: {
250299
target: "viewActive",
251-
actions: assign({
252-
org: (context, event) => event.viewLocation?.org,
253-
package: (context, event) => event.viewLocation?.package,
254-
view: (context, event) => event.viewLocation.view,
255-
documentUri: (context, event) => event.viewLocation.documentUri,
256-
projectPath: (context, event) => event.viewLocation?.projectPath || context?.projectPath,
257-
position: (context, event) => event.viewLocation.position,
258-
identifier: (context, event) => event.viewLocation.identifier,
259-
serviceType: (context, event) => event.viewLocation.serviceType,
260-
type: (context, event) => event.viewLocation?.type,
261-
isGraphql: (context, event) => event.viewLocation?.isGraphql,
262-
metadata: (context, event) => event.viewLocation?.metadata,
263-
addType: (context, event) => event.viewLocation?.addType,
264-
dataMapperMetadata: (context, event) => event.viewLocation?.dataMapperMetadata,
265-
artifactInfo: (context, event) => event.viewLocation?.artifactInfo,
266-
rootDiagramId: (context, event) => event.viewLocation?.rootDiagramId
267-
})
300+
actions: [
301+
assign({
302+
org: (context, event) => event.viewLocation?.org,
303+
package: (context, event) => event.viewLocation?.package,
304+
view: (context, event) => event.viewLocation.view,
305+
documentUri: (context, event) => event.viewLocation.documentUri,
306+
position: (context, event) => event.viewLocation.position,
307+
projectPath: (context, event) => event.viewLocation?.projectPath || context?.projectPath,
308+
identifier: (context, event) => event.viewLocation.identifier,
309+
serviceType: (context, event) => event.viewLocation.serviceType,
310+
type: (context, event) => event.viewLocation?.type,
311+
isGraphql: (context, event) => event.viewLocation?.isGraphql,
312+
metadata: (context, event) => event.viewLocation?.metadata,
313+
addType: (context, event) => event.viewLocation?.addType,
314+
dataMapperMetadata: (context, event) => event.viewLocation?.dataMapperMetadata,
315+
artifactInfo: (context, event) => event.viewLocation?.artifactInfo,
316+
rootDiagramId: (context, event) => event.viewLocation?.rootDiagramId
317+
}),
318+
(context, event) => notifyTreeView(
319+
context.projectPath,
320+
event.viewLocation?.documentUri,
321+
event.viewLocation?.position,
322+
event.viewLocation?.view
323+
)
324+
]
268325
}
269326
}
270327
},
@@ -325,37 +382,53 @@ const stateMachine = createMachine<MachineContext>(
325382
on: {
326383
OPEN_VIEW: {
327384
target: "viewInit",
328-
actions: assign({
329-
view: (context, event) => event.viewLocation.view,
330-
documentUri: (context, event) => event.viewLocation.documentUri,
331-
position: (context, event) => event.viewLocation.position,
332-
identifier: (context, event) => event.viewLocation.identifier,
333-
serviceType: (context, event) => event.viewLocation.serviceType,
334-
projectPath: (context, event) => event.viewLocation?.projectPath || context?.projectPath,
335-
org: (context, event) => event.viewLocation?.org || context?.org,
336-
package: (context, event) => event.viewLocation?.package || context?.package,
337-
type: (context, event) => event.viewLocation?.type,
338-
isGraphql: (context, event) => event.viewLocation?.isGraphql,
339-
metadata: (context, event) => event.viewLocation?.metadata,
340-
addType: (context, event) => event.viewLocation?.addType,
341-
dataMapperMetadata: (context, event) => event.viewLocation?.dataMapperMetadata,
342-
artifactInfo: (context, event) => event.viewLocation?.artifactInfo,
343-
rootDiagramId: (context, event) => event.viewLocation?.rootDiagramId
344-
})
385+
actions: [
386+
assign({
387+
view: (context, event) => event.viewLocation.view,
388+
documentUri: (context, event) => event.viewLocation.documentUri,
389+
position: (context, event) => event.viewLocation.position,
390+
identifier: (context, event) => event.viewLocation.identifier,
391+
serviceType: (context, event) => event.viewLocation.serviceType,
392+
projectPath: (context, event) => event.viewLocation?.projectPath || context?.projectPath,
393+
org: (context, event) => event.viewLocation?.org || context?.org,
394+
package: (context, event) => event.viewLocation?.package || context?.package,
395+
type: (context, event) => event.viewLocation?.type,
396+
isGraphql: (context, event) => event.viewLocation?.isGraphql,
397+
metadata: (context, event) => event.viewLocation?.metadata,
398+
addType: (context, event) => event.viewLocation?.addType,
399+
dataMapperMetadata: (context, event) => event.viewLocation?.dataMapperMetadata,
400+
artifactInfo: (context, event) => event.viewLocation?.artifactInfo,
401+
rootDiagramId: (context, event) => event.viewLocation?.rootDiagramId
402+
}),
403+
(context, event) => notifyTreeView(
404+
event.viewLocation?.projectPath || context?.projectPath,
405+
event.viewLocation?.documentUri,
406+
event.viewLocation?.position,
407+
event.viewLocation?.view
408+
)
409+
]
345410
},
346411
VIEW_UPDATE: {
347412
target: "webViewLoaded",
348-
actions: assign({
349-
documentUri: (context, event) => event.viewLocation.documentUri,
350-
position: (context, event) => event.viewLocation.position,
351-
view: (context, event) => event.viewLocation.view,
352-
identifier: (context, event) => event.viewLocation.identifier,
353-
serviceType: (context, event) => event.viewLocation.serviceType,
354-
type: (context, event) => event.viewLocation?.type,
355-
isGraphql: (context, event) => event.viewLocation?.isGraphql,
356-
addType: (context, event) => event.viewLocation?.addType,
357-
dataMapperMetadata: (context, event) => event.viewLocation?.dataMapperMetadata
358-
})
413+
actions: [
414+
assign({
415+
documentUri: (context, event) => event.viewLocation.documentUri,
416+
position: (context, event) => event.viewLocation.position,
417+
view: (context, event) => event.viewLocation.view,
418+
identifier: (context, event) => event.viewLocation.identifier,
419+
serviceType: (context, event) => event.viewLocation.serviceType,
420+
type: (context, event) => event.viewLocation?.type,
421+
isGraphql: (context, event) => event.viewLocation?.isGraphql,
422+
addType: (context, event) => event.viewLocation?.addType,
423+
dataMapperMetadata: (context, event) => event.viewLocation?.dataMapperMetadata
424+
}),
425+
(context, event) => notifyTreeView(
426+
context.projectPath,
427+
event.viewLocation?.documentUri,
428+
event.viewLocation?.position,
429+
event.viewLocation?.view
430+
)
431+
]
359432
},
360433
FILE_EDIT: {
361434
target: "viewEditing"
@@ -395,7 +468,9 @@ const stateMachine = createMachine<MachineContext>(
395468
fetchProjectInfo: (context, event) => {
396469
return new Promise(async (resolve, reject) => {
397470
try {
398-
const projectInfo = await context.langClient.getProjectInfo({ projectPath: context.workspacePath || context.projectPath });
471+
const projectInfo = await context.langClient.getProjectInfo({
472+
projectPath: context.workspacePath || context.projectPath
473+
});
399474
resolve({ projectInfo });
400475
} catch (error) {
401476
throw new Error("Error occurred while fetching project info.", error);
@@ -945,6 +1020,20 @@ async function handleSingleWorkspaceFolder(workspaceURI: Uri): Promise<ProjectMe
9451020
}
9461021
}
9471022

1023+
function notifyTreeView(
1024+
projectPath?: string,
1025+
documentUri?: string,
1026+
position?: NodePosition,
1027+
view?: MACHINE_VIEW
1028+
) {
1029+
commands.executeCommand(BI_COMMANDS.NOTIFY_PROJECT_EXPLORER, {
1030+
projectPath,
1031+
documentUri,
1032+
position,
1033+
view
1034+
});
1035+
}
1036+
9481037
function setBIContext(isBI: boolean) {
9491038
commands.executeCommand('setContext', 'isBIProject', isBI);
9501039
}

workspaces/bi/bi-extension/src/project-explorer/activate.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* specific language governing permissions and limitations
1616
* under the License.
1717
*/
18-
import { SHARED_COMMANDS, BI_COMMANDS } from '@wso2/ballerina-core';
18+
import { SHARED_COMMANDS, BI_COMMANDS, MACHINE_VIEW, NodePosition } from '@wso2/ballerina-core';
1919

2020
import { ProjectExplorerEntry, ProjectExplorerEntryProvider } from './project-explorer-provider';
2121
import { ExtensionContext, TreeView, commands, window, workspace } from 'vscode';
@@ -39,6 +39,8 @@ export function activateProjectExplorer(config: ExplorerActivationConfig) {
3939
const projectExplorerDataProvider = new ProjectExplorerEntryProvider();
4040
const projectTree = createProjectTree(projectExplorerDataProvider);
4141

42+
projectExplorerDataProvider.setTreeView(projectTree);
43+
4244
if (isBallerinaPackage || isBallerinaWorkspace) {
4345
registerBallerinaCommands(projectExplorerDataProvider, isBI, isBallerinaWorkspace, isEmptyWorkspace);
4446
}
@@ -68,6 +70,17 @@ function registerBallerinaCommands(
6870
isEmptyWorkspace?: boolean
6971
) {
7072
commands.registerCommand(BI_COMMANDS.REFRESH_COMMAND, () => dataProvider.refresh());
73+
commands.registerCommand(
74+
BI_COMMANDS.NOTIFY_PROJECT_EXPLORER,
75+
(event: {
76+
projectPath: string,
77+
documentUri: string,
78+
position: NodePosition,
79+
view: MACHINE_VIEW
80+
}) => {
81+
dataProvider.revealInTreeView(event.documentUri, event.projectPath, event.position, event.view);
82+
}
83+
);
7184
commands.executeCommand('setContext', 'BI.isWorkspaceSupported', extension.isWorkspaceSupported ?? false);
7285

7386
if (isBallerinaWorkspace) {

0 commit comments

Comments
 (0)