Skip to content

Commit

Permalink
This pull request introduces support for TSConfig paths (#233)
Browse files Browse the repository at this point in the history
* TSConfig path alias pushed to workspace config mappings to support TSConfig paths

* demo workplace added
  • Loading branch information
NazmusSayad authored Nov 29, 2024
1 parent 8e4a72d commit 06c4593
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/configuration/tsconfig.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,28 @@ async function findTsConfigFiles(workfolder: vscode.WorkspaceFolder) {

async function createMappingsFromWorkspaceConfig(
tsconfig: {
compilerOptions: { baseUrl: string };
compilerOptions: { baseUrl: string, paths?: Record<string, string[]> };
},
workfolder: vscode.WorkspaceFolder,
showHiddenFiles: boolean,
filesExclude: FilesExclude
): Promise<Mapping[]> {
const mappings: Mapping[] = [];
const baseUrl = tsconfig?.compilerOptions?.baseUrl;
const paths = tsconfig?.compilerOptions?.paths;

if (paths && baseUrl && workfolder) {
for (const alias in paths) {
const destinations = paths[alias];

destinations.forEach((dest) => {
mappings.push({
key: alias.replace(/\*$/, ''),
value: '${workspaceFolder}/' + join(baseUrl, dest.replace(/\*$/, '')),
});
});
}
}

if (baseUrl && workfolder) {
const foldersInBaseUrl = await getFoldersInBaseUrl(
Expand Down
3 changes: 3 additions & 0 deletions src/test/demo-workspace/demo.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
},
{
"path": "project-nixos-config"
},
{
"path": "project-with-paths"
}
],
"settings": {
Expand Down
Empty file.
Empty file.
1 change: 1 addition & 0 deletions src/test/demo-workspace/project-with-paths/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import { } from '@/foo/foo';
9 changes: 9 additions & 0 deletions src/test/demo-workspace/project-with-paths/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"baseUrl": ".",

"paths": {
"@/*": ["./src/*"]
}
}
}

0 comments on commit 06c4593

Please sign in to comment.