Skip to content

Commit 8bc754c

Browse files
committed
Improve package name in top navigation bar
1 parent 07a3d06 commit 8bc754c

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ import {
1919
fetchScope,
2020
getOrgPackageName,
2121
UndoRedoManager,
22-
getProjectTomlValues,
23-
getWorkspaceTomlValues
22+
getPackageName
2423
} from './utils';
2524
import { buildProjectsStructure } from './utils/project-artifacts';
2625
import { runCommandWithOutput } from './utils/runCommand';
@@ -516,8 +515,7 @@ const stateMachine = createMachine<MachineContext>(
516515
},
517516
findView(context, event): Promise<void> {
518517
return new Promise(async (resolve, reject) => {
519-
const projectTomlValues = context.projectPath ? await getProjectTomlValues(context.projectPath) : undefined;
520-
const packageName = projectTomlValues?.package?.name;
518+
const packageName = getPackageName(context.projectInfo, context.projectPath);
521519
if (!context.view && context.langClient) {
522520
if (!context.position || ("groupId" in context.position)) {
523521
if (!context.projectPath && context.workspacePath) {

workspaces/ballerina/ballerina-extension/src/utils/config.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* under the License.
1717
*/
1818

19-
import { SemanticVersion, PackageTomlValues, SCOPE, WorkspaceTomlValues } from '@wso2/ballerina-core';
19+
import { SemanticVersion, PackageTomlValues, SCOPE, WorkspaceTomlValues, ProjectInfo } from '@wso2/ballerina-core';
2020
import { BallerinaExtension } from '../core';
2121
import { WorkspaceConfiguration, workspace, Uri, RelativePattern } from 'vscode';
2222
import * as fs from 'fs';
@@ -356,3 +356,21 @@ export function setupBIFiles(projectDir: string): void {
356356
}
357357
});
358358
}
359+
360+
export function getPackageName(projectInfo: ProjectInfo, projectPath: string): string {
361+
if (!projectPath || !projectInfo) {
362+
return "";
363+
}
364+
365+
if (projectInfo.children?.length) {
366+
const matchedProject = projectInfo.children.find(
367+
(child) => child.projectPath === projectPath
368+
);
369+
370+
if (matchedProject) {
371+
return matchedProject.title || matchedProject.name;
372+
}
373+
}
374+
375+
return projectInfo.title || projectInfo.name;
376+
}

0 commit comments

Comments
 (0)