diff --git a/src/lens.ts b/src/lens.ts index a60037a..40f2e7a 100644 --- a/src/lens.ts +++ b/src/lens.ts @@ -9,6 +9,7 @@ import { cleanFilename } from './utils'; import logger from './log'; import { InfracostCommand } from './command'; import context from './context'; +import path = require('path'); export default class InfracostLensProvider implements CodeLensProvider { workspace: Workspace; @@ -26,12 +27,11 @@ export default class InfracostLensProvider implements CodeLensProvider { } const lenses: CodeLens[] = []; - const filename = cleanFilename(document.uri.path); + const filename = document.uri.fsPath; logger.debug(`providing codelens for file ${filename}`); - const blocks = this.workspace.project(filename); for (const block of Object.values(blocks)) { - if (block.filename !== filename) { + if (block.filename.toLowerCase() !== filename.toLowerCase()) { continue; } diff --git a/src/workspace.ts b/src/workspace.ts index be0f1f3..b52e9da 100644 --- a/src/workspace.ts +++ b/src/workspace.ts @@ -155,10 +155,12 @@ export default class Workspace { // TODO: determine or allow users to switch the project they are using. project(filename: string): { [key: string]: Block } { - const projects = this.filesToProjects[filename]; - - if (projects && Object.keys(projects).length > 0) { - const project = Object.keys(projects)[0]; + const key = filename.split(path.sep).join('/'); + const projectKey = this.filesToProjects[Object.keys(this.filesToProjects).find((k: string) => k.toLowerCase() === key.toLowerCase()) || key]; + + + if (projectKey && Object.keys(projectKey).length > 0) { + const project = Object.keys(projectKey)[0]; return this.projects[project].blocks; } @@ -302,7 +304,7 @@ export default class Workspace { const formatted = new Project(name, projectPath, this.currency, this.blockTemplate); for (const resource of project.breakdown.resources) { for (const call of resource.metadata.calls) { - const filename = path.resolve(cleanFilename(call.filename)); + const filename = cleanFilename(path.resolve(call.filename)); logger.debug(`adding file: ${filename} to project: ${projectPath}`); formatted.setBlock(filename, call.blockName, call.startLine).resources.push(resource); @@ -327,10 +329,11 @@ export default class Workspace { } private addProjectToFile(filename: string, projectPath: string) { - if (this.filesToProjects[filename] === undefined) { - this.filesToProjects[filename] = {}; + const key = filename.split(path.sep).join('/'); + if (this.filesToProjects[key] === undefined) { + this.filesToProjects[key] = {}; } - this.filesToProjects[filename][projectPath] = true; + this.filesToProjects[key][projectPath] = true; } }