Skip to content

Commit 36af9db

Browse files
committed
fix(namespace): normalize paths before path operations on Windows
- Fix NamespaceGenerator extracting directory path before normalizing backslashes, causing namespace generation to fail on Windows (issue #130) - Fix NamespaceResolver vendor path detection to work with backslash paths on Windows
1 parent 34bc312 commit 36af9db

2 files changed

Lines changed: 3 additions & 5 deletions

File tree

src/core/NamespaceGenerator.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ export class NamespaceGenerator {
99
async generate(editor: vscode.TextEditor): Promise<void> {
1010
const currentUri = editor.document.uri;
1111
const currentFile = currentUri.fsPath;
12-
const currentPath = currentFile.substring(0, currentFile.lastIndexOf('/'));
13-
14-
const normalizedCurrentPath = currentPath.replace(/\\/g, '/');
1512
const normalizedCurrentFile = currentFile.replace(/\\/g, '/');
13+
const normalizedCurrentPath = normalizedCurrentFile.substring(0, normalizedCurrentFile.lastIndexOf('/'));
1614

1715
const workspaceFolder = vscode.workspace.getWorkspaceFolder(currentUri);
1816
if (!workspaceFolder) {

src/core/NamespaceResolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class NamespaceResolver {
1313
const cached = this.cache.lookup(className);
1414
if (cached.length > 0) {
1515
for (const entry of cached) {
16-
const source = entry.uri.fsPath.includes('/vendor/') ? 'vendor' : 'project';
16+
const source = entry.uri.fsPath.replace(/\\/g, '/').includes('/vendor/') ? 'vendor' : 'project';
1717
results.push({ fqcn: entry.fqcn, source });
1818
}
1919
} else {
@@ -91,7 +91,7 @@ export class NamespaceResolver {
9191
const fqcn = `${namespace}\\${className}`;
9292
if (!seen.has(fqcn)) {
9393
seen.add(fqcn);
94-
const source = file.fsPath.includes('/vendor/') ? 'vendor' : 'project';
94+
const source = file.fsPath.replace(/\\/g, '/').includes('/vendor/') ? 'vendor' : 'project';
9595
results.push({ fqcn, source });
9696
}
9797
}

0 commit comments

Comments
 (0)