Skip to content

Commit

Permalink
fix: use findProjectWithPath function within codelens (#1437)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli authored Dec 10, 2022
1 parent ed78721 commit c5fa99a
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions libs/vscode/nx-workspace/src/lib/workspace-codelens-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from './find-workspace-json-target';
import { getNxWorkspace } from './get-nx-workspace';
import { join } from 'path';
import { findProjectWithPath } from './find-project-with-path';

export class TargetCodeLens extends CodeLens {
constructor(
Expand Down Expand Up @@ -73,21 +74,17 @@ export class WorkspaceCodeLensProvider implements CodeLensProvider {
const lens: CodeLens[] = [];

let projectName = '';
const { workspace, workspacePath } = await getNxWorkspace();
const { workspacePath } = await getNxWorkspace();

const documentPath = document.uri.path;

if (documentPath.endsWith('project.json')) {
for (const [key, project] of Object.entries(workspace.projects)) {
const documentPathBelongsToProject = documentPath
.replace(/\\/g, '/')
.endsWith(`${project.root}/project.json`);
const documentPathBelongsToRootProject =
join(workspacePath, 'project.json') === documentPath;
if (documentPathBelongsToProject || documentPathBelongsToRootProject) {
projectName = key;
break;
}
const project = await findProjectWithPath(documentPath, workspacePath);
if (!project) {
return;
} else {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
projectName = project.name!;
}
}

Expand Down

0 comments on commit c5fa99a

Please sign in to comment.