From c5fa99a92496d69a4fe05ed81cd6484e5b19b61d Mon Sep 17 00:00:00 2001 From: Jonathan Cammisuli Date: Fri, 9 Dec 2022 19:36:30 -0500 Subject: [PATCH] fix: use `findProjectWithPath` function within codelens (#1437) --- .../src/lib/workspace-codelens-provider.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/libs/vscode/nx-workspace/src/lib/workspace-codelens-provider.ts b/libs/vscode/nx-workspace/src/lib/workspace-codelens-provider.ts index c620d660c1..a60d313ed1 100644 --- a/libs/vscode/nx-workspace/src/lib/workspace-codelens-provider.ts +++ b/libs/vscode/nx-workspace/src/lib/workspace-codelens-provider.ts @@ -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( @@ -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!; } }