Skip to content

Commit

Permalink
Solved issue that not all shorthands were found (#53)
Browse files Browse the repository at this point in the history
* Solved issue that not all shorthands were found

* Format file

* Fix unittests
  • Loading branch information
JordyMackay authored Oct 13, 2022
1 parent 9f359fb commit c2fd26d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/src/importMatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 5 additions & 4 deletions server/src/omtDocumentInformationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/;

Expand All @@ -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) { }

Expand Down Expand Up @@ -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<string, string>(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');
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion server/src/test/omtDocumentInformationProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c2fd26d

Please sign in to comment.