Skip to content

Commit

Permalink
feat(ignoreTsConfigBaseUrl): implemented
Browse files Browse the repository at this point in the history
Resolves #161
  • Loading branch information
ChristianKohler committed Nov 22, 2021
1 parent 5a5d3a8 commit fb323d9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ would allow to type:
}
```

You can disable this behaviour by setting it to false:

```javascript
{
"path-intellisense.ignoreTsConfigBaseUrl": false,
}
```

## Settings

### File extension in import statements
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
"type": "boolean",
"default": true,
"description": "Sets an absolute path to the current workspace"
},
"path-intellisense.ignoreTsConfigBaseUrl": {
"type": "boolean",
"default": false,
"description": "Ignores tsconfig file for mappings"
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/configuration/configuration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ async function getMappings(
workfolder?: vscode.WorkspaceFolder
): Promise<Mapping[]> {
const mappings = parseMappings(configuration["mappings"]);
const tsConfigMappings = await getWorkfolderTsConfigConfiguration(workfolder);
const ignoreTsConfigBaseUrl = configuration["ignoreTsConfigBaseUrl"];
const tsConfigMappings = await (ignoreTsConfigBaseUrl ? [] : getWorkfolderTsConfigConfiguration(workfolder));
const allMappings = [...mappings, ...tsConfigMappings];
return replaceWorkspaceFolder(allMappings, workfolder);
}
2 changes: 1 addition & 1 deletion src/test/demo-workspace/project-one/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"compilerOptions": {
"baseUrl": "baseurl-one"
}
}
}
25 changes: 21 additions & 4 deletions src/test/suite/configuration.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ async function setConfig(key: string, value: any) {
}

suite("Configuration Service", () => {

beforeEach(async () => {
await setConfig("absolutePathToWorkspace", undefined);
await setConfig("extensionOnImport", undefined);
await setConfig("mappings", undefined);
})

await setConfig("ignoreTsConfigBaseUrl", undefined);
});

afterEach(async () => {
await setConfig("absolutePathToWorkspace", undefined);
await setConfig("extensionOnImport", undefined);
await setConfig("mappings", undefined);
})
await setConfig("ignoreTsConfigBaseUrl", undefined);
});

test("has different configuration for the workspaceFolders", async () => {
await subscribeToTsConfigChanges();
Expand Down Expand Up @@ -103,6 +104,22 @@ suite("Configuration Service", () => {
assert.equal(configuration?.mappings.length, 0);
});

test("does not use tsconfig is diabled", async () => {
await subscribeToTsConfigChanges();

const documentOne = await openDocument(
"demo-workspace/project-one/index.js"
);
const configuration = await getConfiguration(documentOne.uri);

await setConfig("ignoreTsConfigBaseUrl", true);

const configurationNew = await getConfiguration(documentOne.uri);

assert.equal(configuration?.mappings.length, 1);
assert.equal(configurationNew?.mappings.length, 0);
});

test("updates configuration on tsconfig change", async () => {
await subscribeToTsConfigChanges();

Expand Down

0 comments on commit fb323d9

Please sign in to comment.