Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ export const BI_COMMANDS = {
ADD_NATURAL_FUNCTION: 'BI.project-explorer.add-natural-function',
TOGGLE_TRACE_LOGS: 'BI.toggle.trace.logs',
ADD_INTEGRATION: 'BI.project-explorer.add-integration',
NOTIFY_PROJECT_EXPLORER: 'BI.project-explorer.notify',
};
219 changes: 154 additions & 65 deletions workspaces/ballerina/ballerina-extension/src/stateMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,38 @@
import { ExtendedLangClient } from './core';
import { createMachine, assign, interpret } from 'xstate';
import { activateBallerina } from './extension';
import { EVENT_TYPE, SyntaxTree, History, MachineStateValue, IUndoRedoManager, VisualizerLocation, webviewReady, MACHINE_VIEW, DIRECTORY_MAP, SCOPE, ProjectStructureResponse, ProjectStructureArtifactResponse, CodeData, ProjectDiagnosticsResponse, Type, dependencyPullProgress } from "@wso2/ballerina-core";
import {
EVENT_TYPE,
SyntaxTree,
History,
MachineStateValue,
IUndoRedoManager,
VisualizerLocation,
webviewReady,
MACHINE_VIEW,
DIRECTORY_MAP,
SCOPE,
ProjectStructureResponse,
ProjectStructureArtifactResponse,
CodeData,
ProjectDiagnosticsResponse,
Type,
dependencyPullProgress,
BI_COMMANDS,
NodePosition
} from "@wso2/ballerina-core";
import { fetchAndCacheLibraryData } from './features/library-browser';
import { VisualizerWebview } from './views/visualizer/webview';
import { commands, extensions, Uri, window, workspace, WorkspaceFolder } from 'vscode';
import { notifyCurrentWebview, RPCLayer } from './RPCLayer';
import { generateUid, getComponentIdentifier, getNodeByIndex, getNodeByName, getNodeByUid, getView } from './utils/state-machine-utils';
import {
generateUid,
getComponentIdentifier,
getNodeByIndex,
getNodeByName,
getNodeByUid,
getView
} from './utils/state-machine-utils';
import * as path from 'path';
import { extension } from './BalExtensionContext';
import { AIStateMachine } from './views/ai-panel/aiMachine';
Expand Down Expand Up @@ -89,6 +115,7 @@ const stateMachine = createMachine<MachineContext>(
async (context, event) => {
await buildProjectsStructure(context.projectInfo, StateMachine.langClient(), true);
notifyCurrentWebview();
notifyTreeView(event.projectPath, context.documentUri, context.position, context.view);
// Resolve the next pending promise waiting for project root update completion
pendingProjectRootUpdateResolvers.shift()?.();
}
Expand Down Expand Up @@ -137,7 +164,13 @@ const stateMachine = createMachine<MachineContext>(
position: (context, event) => event.viewLocation.position ? event.viewLocation.position : context.position,
identifier: (context, event) => event.viewLocation.identifier ? event.viewLocation.identifier : context.identifier,
addType: (context, event) => event.viewLocation?.addType !== undefined ? event.viewLocation.addType : context?.addType,
})
}),
(context, event) => notifyTreeView(
context.projectPath,
event.viewLocation.documentUri || context.documentUri,
event.viewLocation.position || context.position,
context.view
)
]
}
},
Expand All @@ -149,26 +182,42 @@ const stateMachine = createMachine<MachineContext>(
{
target: "renderInitialView",
cond: (context, event) => event.data && event.data.isBI,
actions: assign({
isBI: (context, event) => event.data.isBI,
projectPath: (context, event) => event.data.projectPath,
workspacePath: (context, event) => event.data.workspacePath,
scope: (context, event) => event.data.scope,
org: (context, event) => event.data.orgName,
package: (context, event) => event.data.packageName
})
actions: [
assign({
isBI: (context, event) => event.data.isBI,
projectPath: (context, event) => event.data.projectPath,
workspacePath: (context, event) => event.data.workspacePath,
scope: (context, event) => event.data.scope,
org: (context, event) => event.data.orgName,
package: (context, event) => event.data.packageName
}),
(context, event) => notifyTreeView(
event.data.projectPath,
context.documentUri,
context.position,
context.view
)
]
},
{
target: "activateLS",
cond: (context, event) => event.data && event.data.isBI === false,
actions: assign({
isBI: (context, event) => event.data.isBI,
projectPath: (context, event) => event.data.projectPath,
workspacePath: (context, event) => event.data.workspacePath,
scope: (context, event) => event.data.scope,
org: (context, event) => event.data.orgName,
package: (context, event) => event.data.packageName
})
actions: [
assign({
isBI: (context, event) => event.data.isBI,
projectPath: (context, event) => event.data.projectPath,
workspacePath: (context, event) => event.data.workspacePath,
scope: (context, event) => event.data.scope,
org: (context, event) => event.data.orgName,
package: (context, event) => event.data.packageName
}),
(context, event) => notifyTreeView(
event.data.projectPath,
context.documentUri,
context.position,
context.view
)
]
}
],
onError: {
Expand Down Expand Up @@ -248,23 +297,31 @@ const stateMachine = createMachine<MachineContext>(
on: {
OPEN_VIEW: {
target: "viewActive",
actions: assign({
org: (context, event) => event.viewLocation?.org,
package: (context, event) => event.viewLocation?.package,
view: (context, event) => event.viewLocation.view,
documentUri: (context, event) => event.viewLocation.documentUri,
projectPath: (context, event) => event.viewLocation?.projectPath || context?.projectPath,
position: (context, event) => event.viewLocation.position,
identifier: (context, event) => event.viewLocation.identifier,
serviceType: (context, event) => event.viewLocation.serviceType,
type: (context, event) => event.viewLocation?.type,
isGraphql: (context, event) => event.viewLocation?.isGraphql,
metadata: (context, event) => event.viewLocation?.metadata,
addType: (context, event) => event.viewLocation?.addType,
dataMapperMetadata: (context, event) => event.viewLocation?.dataMapperMetadata,
artifactInfo: (context, event) => event.viewLocation?.artifactInfo,
rootDiagramId: (context, event) => event.viewLocation?.rootDiagramId
})
actions: [
assign({
org: (context, event) => event.viewLocation?.org,
package: (context, event) => event.viewLocation?.package,
view: (context, event) => event.viewLocation.view,
documentUri: (context, event) => event.viewLocation.documentUri,
position: (context, event) => event.viewLocation.position,
projectPath: (context, event) => event.viewLocation?.projectPath || context?.projectPath,
identifier: (context, event) => event.viewLocation.identifier,
serviceType: (context, event) => event.viewLocation.serviceType,
type: (context, event) => event.viewLocation?.type,
isGraphql: (context, event) => event.viewLocation?.isGraphql,
metadata: (context, event) => event.viewLocation?.metadata,
addType: (context, event) => event.viewLocation?.addType,
dataMapperMetadata: (context, event) => event.viewLocation?.dataMapperMetadata,
artifactInfo: (context, event) => event.viewLocation?.artifactInfo,
rootDiagramId: (context, event) => event.viewLocation?.rootDiagramId
}),
(context, event) => notifyTreeView(
context.projectPath,
event.viewLocation?.documentUri,
event.viewLocation?.position,
event.viewLocation?.view
)
]
}
}
},
Expand Down Expand Up @@ -325,37 +382,53 @@ const stateMachine = createMachine<MachineContext>(
on: {
OPEN_VIEW: {
target: "viewInit",
actions: assign({
view: (context, event) => event.viewLocation.view,
documentUri: (context, event) => event.viewLocation.documentUri,
position: (context, event) => event.viewLocation.position,
identifier: (context, event) => event.viewLocation.identifier,
serviceType: (context, event) => event.viewLocation.serviceType,
projectPath: (context, event) => event.viewLocation?.projectPath || context?.projectPath,
org: (context, event) => event.viewLocation?.org || context?.org,
package: (context, event) => event.viewLocation?.package || context?.package,
type: (context, event) => event.viewLocation?.type,
isGraphql: (context, event) => event.viewLocation?.isGraphql,
metadata: (context, event) => event.viewLocation?.metadata,
addType: (context, event) => event.viewLocation?.addType,
dataMapperMetadata: (context, event) => event.viewLocation?.dataMapperMetadata,
artifactInfo: (context, event) => event.viewLocation?.artifactInfo,
rootDiagramId: (context, event) => event.viewLocation?.rootDiagramId
})
actions: [
assign({
view: (context, event) => event.viewLocation.view,
documentUri: (context, event) => event.viewLocation.documentUri,
position: (context, event) => event.viewLocation.position,
identifier: (context, event) => event.viewLocation.identifier,
serviceType: (context, event) => event.viewLocation.serviceType,
projectPath: (context, event) => event.viewLocation?.projectPath || context?.projectPath,
org: (context, event) => event.viewLocation?.org || context?.org,
package: (context, event) => event.viewLocation?.package || context?.package,
type: (context, event) => event.viewLocation?.type,
isGraphql: (context, event) => event.viewLocation?.isGraphql,
metadata: (context, event) => event.viewLocation?.metadata,
addType: (context, event) => event.viewLocation?.addType,
dataMapperMetadata: (context, event) => event.viewLocation?.dataMapperMetadata,
artifactInfo: (context, event) => event.viewLocation?.artifactInfo,
rootDiagramId: (context, event) => event.viewLocation?.rootDiagramId
}),
(context, event) => notifyTreeView(
event.viewLocation?.projectPath || context?.projectPath,
event.viewLocation?.documentUri,
event.viewLocation?.position,
event.viewLocation?.view
)
]
},
VIEW_UPDATE: {
target: "webViewLoaded",
actions: assign({
documentUri: (context, event) => event.viewLocation.documentUri,
position: (context, event) => event.viewLocation.position,
view: (context, event) => event.viewLocation.view,
identifier: (context, event) => event.viewLocation.identifier,
serviceType: (context, event) => event.viewLocation.serviceType,
type: (context, event) => event.viewLocation?.type,
isGraphql: (context, event) => event.viewLocation?.isGraphql,
addType: (context, event) => event.viewLocation?.addType,
dataMapperMetadata: (context, event) => event.viewLocation?.dataMapperMetadata
})
actions: [
assign({
documentUri: (context, event) => event.viewLocation.documentUri,
position: (context, event) => event.viewLocation.position,
view: (context, event) => event.viewLocation.view,
identifier: (context, event) => event.viewLocation.identifier,
serviceType: (context, event) => event.viewLocation.serviceType,
type: (context, event) => event.viewLocation?.type,
isGraphql: (context, event) => event.viewLocation?.isGraphql,
addType: (context, event) => event.viewLocation?.addType,
dataMapperMetadata: (context, event) => event.viewLocation?.dataMapperMetadata
}),
(context, event) => notifyTreeView(
context.projectPath,
event.viewLocation?.documentUri,
event.viewLocation?.position,
event.viewLocation?.view
)
]
},
FILE_EDIT: {
target: "viewEditing"
Expand Down Expand Up @@ -395,7 +468,9 @@ const stateMachine = createMachine<MachineContext>(
fetchProjectInfo: (context, event) => {
return new Promise(async (resolve, reject) => {
try {
const projectInfo = await context.langClient.getProjectInfo({ projectPath: context.workspacePath || context.projectPath });
const projectInfo = await context.langClient.getProjectInfo({
projectPath: context.workspacePath || context.projectPath
});
resolve({ projectInfo });
} catch (error) {
throw new Error("Error occurred while fetching project info.", error);
Expand Down Expand Up @@ -945,6 +1020,20 @@ async function handleSingleWorkspaceFolder(workspaceURI: Uri): Promise<ProjectMe
}
}

function notifyTreeView(
projectPath?: string,
documentUri?: string,
position?: NodePosition,
view?: MACHINE_VIEW
) {
commands.executeCommand(BI_COMMANDS.NOTIFY_PROJECT_EXPLORER, {
projectPath,
documentUri,
position,
view
});
}

function setBIContext(isBI: boolean) {
commands.executeCommand('setContext', 'isBIProject', isBI);
}
15 changes: 14 additions & 1 deletion workspaces/bi/bi-extension/src/project-explorer/activate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { SHARED_COMMANDS, BI_COMMANDS } from '@wso2/ballerina-core';
import { SHARED_COMMANDS, BI_COMMANDS, MACHINE_VIEW, NodePosition } from '@wso2/ballerina-core';

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

projectExplorerDataProvider.setTreeView(projectTree);

if (isBallerinaPackage || isBallerinaWorkspace) {
registerBallerinaCommands(projectExplorerDataProvider, isBI, isBallerinaWorkspace, isEmptyWorkspace);
}
Expand Down Expand Up @@ -68,6 +70,17 @@ function registerBallerinaCommands(
isEmptyWorkspace?: boolean
) {
commands.registerCommand(BI_COMMANDS.REFRESH_COMMAND, () => dataProvider.refresh());
commands.registerCommand(
BI_COMMANDS.NOTIFY_PROJECT_EXPLORER,
(event: {
projectPath: string,
documentUri: string,
position: NodePosition,
view: MACHINE_VIEW
}) => {
dataProvider.revealInTreeView(event.documentUri, event.projectPath, event.position, event.view);
}
);
commands.executeCommand('setContext', 'BI.isWorkspaceSupported', extension.isWorkspaceSupported ?? false);

if (isBallerinaWorkspace) {
Expand Down
Loading
Loading