diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ab9e81..05d2a7f 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. This plugin uses [Semantic versioning](https://semver.org). +## [2.12.4] - 2022-10-11 + +### Fixed + +- Solved issue that not all shorthands were found + ## [2.12.3] - 2022-08-12 ### Security diff --git a/server/src/importMatch.ts b/server/src/importMatch.ts index ea96f15..8d1756c 100755 --- a/server/src/importMatch.ts +++ b/server/src/importMatch.ts @@ -43,7 +43,7 @@ function toAbsolutePath(document: TextDocument, link: string): string { * Convert the uri to a path to a directory and make sure it does not start with `file://` * @param uri path to be made into a dirpath */ -function dirpath(uri: string): string { +export function dirpath(uri: string): string { uri = dirname(uri); return uri.startsWith('file:') ? uri.substr(7) : uri; } diff --git a/server/src/omtDocumentInformationProvider.ts b/server/src/omtDocumentInformationProvider.ts index d19fee4..d04458e 100755 --- a/server/src/omtDocumentInformationProvider.ts +++ b/server/src/omtDocumentInformationProvider.ts @@ -7,7 +7,7 @@ import { WorkspaceLookup } from './workspaceLookup'; import { DeclaredImportLinkData, isDeclaredImportLinkData, OmtAvailableObjects, OmtDocumentInformation, OmtImport, OmtLocalObject } from './types'; import { YAMLError } from 'yaml/util'; import { getAvailableObjectsFromDocument } from './omtAvailableObjectsProvider'; -import { getDiMatch } from './importMatch'; +import { dirpath, getDiMatch } from './importMatch'; const newLine = /\r?\n/; @@ -16,7 +16,7 @@ const newLine = /\r?\n/; */ export default class OmtDocumentInformationProvider { - private tsConfigFiles = glob.sync('**/tsconfig**.json'); + private tsConfigFiles = glob.sync('**/tsconfig**.json', { realpath: true }); constructor(private workspaceLookup: WorkspaceLookup) { } @@ -59,9 +59,10 @@ export default class OmtDocumentInformationProvider { * @param document the document that needs context. */ private contextPaths(document: TextDocument) { + const dirpathValue = dirpath(document.uri); return new Map(this.tsConfigFiles // we need to filter for same parent because another config may have some of the same paths - .filter(uri => document.uri.startsWith(uri.substr(0, uri.lastIndexOf('/')))) + .filter(uri => dirpathValue.startsWith(uri.substring(0, uri.lastIndexOf('/')))) .reduce((paths: [string, string][], uri: string) => { try { const file = readFileSync(uri, 'utf8'); @@ -71,7 +72,7 @@ export default class OmtDocumentInformationProvider { for (const key in json.compilerOptions.paths) { const relPath = json.compilerOptions.paths[key].toString(); const newPath = resolve(dirname(uri), relPath); - paths.push([key.substr(0, key.lastIndexOf('/*')), newPath]); + paths.push([key.substring(0, key.lastIndexOf('/*')), newPath]); } } } catch (e) { diff --git a/server/src/test/omtDocumentInformationProvider.test.ts b/server/src/test/omtDocumentInformationProvider.test.ts index 1e20b4d..792b31e 100755 --- a/server/src/test/omtDocumentInformationProvider.test.ts +++ b/server/src/test/omtDocumentInformationProvider.test.ts @@ -38,7 +38,7 @@ describe('OMTLinkProvider', () => { beforeEach(() => { const uri = 'testFixture/one/imports.omt'; - const textDocument = TextDocument.create(uri, 'omt', 1, readFileSync(resolve(uri)).toString()); + const textDocument = TextDocument.create(resolve(uri), 'omt', 1, readFileSync(resolve(uri)).toString()); const errorStub = stub(console, 'error'); actualDocumentLinks = linkProvider.provideDocumentInformation(textDocument).documentLinks; //- called in the catch clause for reading tsconfig-invalid