Skip to content

Commit 0950eb7

Browse files
Merge pull request #3456 from opral/sherl-171-fix-sherlock-v2-ot-working-on-windows
fix: sherlock v2 on win
2 parents accf629 + 5a991cd commit 0950eb7

File tree

4 files changed

+45
-17
lines changed

4 files changed

+45
-17
lines changed

.changeset/wise-pillows-applaud.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"vs-code-extension": patch
3+
"@inlang/sdk": patch
4+
---
5+
6+
fix sdk&sherlock on win

inlang/packages/sdk/src/project/loadProjectFromDirectory.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -705,21 +705,33 @@ export function withAbsolutePaths(
705705
* Joins a path from a project path.
706706
*
707707
* @example
708-
* joinPathFromProject("/project.inlang", "./local-plugins/mock-plugin.js") -> "/local-plugins/mock-plugin.js"
708+
* absolutePathFromProject("/project.inlang", "./local-plugins/mock-plugin.js") -> "/local-plugins/mock-plugin.js"
709709
*
710-
* joinPathFromProject("/website/project.inlang", "./mock-plugin.js") -> "/website/mock-plugin.js"
710+
* absolutePathFromProject("/website/project.inlang", "./mock-plugin.js") -> "/website/mock-plugin.js"
711711
*/
712-
export function absolutePathFromProject(projectPath: string, path: string) {
713-
// need to remove the project path from the module path for legacy reasons
714-
// "/project.inlang/local-plugins/mock-plugin.js" -> "/local-plugins/mock-plugin.js"
715-
const pathWithoutProject = projectPath
716-
.split(nodePath.sep)
717-
.slice(0, -1)
718-
.join(nodePath.sep);
712+
export function absolutePathFromProject(
713+
projectPath: string,
714+
filePath: string
715+
): string {
716+
// Normalize paths for consistency across platforms
717+
const normalizedProjectPath = nodePath
718+
.normalize(projectPath)
719+
.replace(/\\/g, "/");
720+
const normalizedFilePath = nodePath.normalize(filePath).replace(/\\/g, "/");
721+
722+
// Remove the last part of the project path (file name) to get the project root
723+
const projectRoot = nodePath.dirname(normalizedProjectPath);
724+
725+
// If filePath is already absolute, return it directly
726+
if (nodePath.isAbsolute(normalizedFilePath)) {
727+
return normalizedFilePath;
728+
}
719729

720-
const resolvedPath = nodePath.resolve(pathWithoutProject, path);
730+
// Compute absolute resolved path
731+
const resolvedPath = nodePath.resolve(projectRoot, normalizedFilePath);
721732

722-
return resolvedPath;
733+
// Ensure final path always uses forward slashes
734+
return resolvedPath.replace(/\\/g, "/");
723735
}
724736

725737
export class ResourceFileImportError extends Error {

inlang/packages/sherlock/src/utilities/project/project.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,25 @@ export function createProjectViewNodes(args: {
4444
}
4545

4646
const projectPath = typeof project.projectPath === "string" ? project.projectPath : ""
47-
const projectName = projectPath.split("/").slice(-1).join("/").replace(".inlang", "")
48-
const relativePath =
49-
"./" + path.normalize(projectPath.replace(args.workspaceFolder.uri.fsPath, "./"))
47+
48+
// Ensure forward slashes are used across platforms
49+
const normalizedProjectPath = projectPath.split(path.sep).join("/")
50+
51+
// Extract project name safely
52+
const projectName = normalizedProjectPath.split("/").slice(-1).join("/").replace(".inlang", "")
53+
54+
// Compute relative path
55+
const relativePath = path
56+
.relative(args.workspaceFolder.uri.fsPath, projectPath) // Get relative path
57+
.split(path.sep) // Normalize separators
58+
.join("/") // Ensure forward slashes for cross-platform compatibility
59+
60+
const finalRelativePath = `./${relativePath}`
5061

5162
return {
5263
label: projectName,
5364
path: project.projectPath,
54-
relativePath: relativePath,
65+
relativePath: finalRelativePath,
5566
isSelected: project.projectPath === state().selectedProjectPath,
5667
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
5768
context: args.context,
@@ -95,6 +106,7 @@ export async function handleTreeSelection(args: {
95106
}))
96107

97108
const newSelectedProject = projectViewNodes.find((node) => node.isSelected)?.path as string
109+
console.log(newSelectedProject)
98110

99111
try {
100112
const localAccount = getLocalAccount({ fs })

pnpm-lock.yaml

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)