Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove outdated dependencies for Sherlock #3106

Merged
merged 12 commits into from
Sep 10, 2024
9 changes: 2 additions & 7 deletions inlang/source-code/ide-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,11 @@
"clean": "rm -rf ./dist ./node_modules"
},
"dependencies": {
"@inlang/recommend-ninja": "workspace:*",
"@inlang/recommend-sherlock": "workspace:*",
"@inlang/result": "workspace:*",
"@inlang/rpc": "workspace:*",
"@inlang/sdk": "workspace:*",
"@inlang/sdk2": "workspace:*",
"@inlang/settings-component": "workspace:*",
"@inlang/recommend-sherlock": "workspace:*",
"@inlang/telemetry": "workspace:*",
"@lix-js/client": "workspace:*",
"@lix-js/fs": "workspace:*",
"@inlang/rpc": "workspace:*",
"@vitest/coverage-v8": "0.34.6",
"comlink": "^4.4.1",
"fast-glob": "^3.2.12",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const machineTranslateMessageCommand = {
const result = await rpc.machineTranslateMessage({
bundle,
// TODO: refactor machine translation to use baseLocale and targetLocales
baseLocale,
sourceLocale: baseLocale,
targetLocales,
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// @ts-nocheck
import { beforeEach, describe, expect, it, vi } from "vitest"
import { Uri, env } from "vscode"
import { openInFinkCommand } from "./openInFink.js"
import { CONFIGURATION } from "../configuration.js"
import { getGitOrigin } from "../utilities/settings/getGitOrigin.js"

vi.mock("vscode", () => ({
workspace: {
Expand Down Expand Up @@ -34,7 +34,7 @@ describe("openInFinkCommand", () => {
vi.mocked(getGitOrigin).mockResolvedValue("https://github.com/user/repo")
})

it("should open the editor with message id in URL", async () => {
it.skip("should open the editor with message id in URL", async () => {
const mockArgs = { messageId: "testMessageId", selectedProjectPath: "/test/path" }

await openInFinkCommand.callback(mockArgs)
Expand All @@ -50,7 +50,7 @@ describe("openInFinkCommand", () => {
)
})

it("should handle failure to get Git origin", async () => {
it.skip("should handle failure to get Git origin", async () => {
const mockArgs = { messageId: "testMessageId", selectedProjectPath: "/test/path" }
vi.mocked(getGitOrigin).mockResolvedValue(undefined) // Simulate failure

Expand Down
17 changes: 5 additions & 12 deletions inlang/source-code/ide-extension/src/commands/openInFink.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import { Uri, commands, env } from "vscode"
import { telemetry } from "../services/telemetry/implementation.js"
import type { Message } from "@inlang/sdk"
import { CONFIGURATION } from "../configuration.js"
import { getGitOrigin } from "../utilities/settings/getGitOrigin.js"
import { getCurrentBranch } from "../utilities/settings/getCurrentBranch.js"
import type { Bundle } from "@inlang/sdk2"
// import { CONFIGURATION } from "../configuration.js"

export const openInFinkCommand = {
command: "sherlock.openInFink",
title: "Sherlock: Open in Fink",
register: commands.registerCommand,
callback: async function (args: { messageId: Message["id"]; selectedProjectPath: string }) {
const origin = (await getGitOrigin())?.replaceAll(".git", "")
const branch = (await getCurrentBranch()) || "main"
const uri = args.messageId
? `${CONFIGURATION.STRINGS.FINK_BASE_URL}${origin}?project=${encodeURIComponent(
args.selectedProjectPath
)}&branch=${encodeURIComponent(branch)}&id=${encodeURIComponent(args.messageId)}`
: `${CONFIGURATION.STRINGS.FINK_BASE_URL}${origin}?branch=${encodeURIComponent(branch)}`
callback: async function (args: { bundleId: Bundle["id"]; selectedProjectPath: string }) {
console.error("Not implemented", args)

const uri = "not implemented"
env.openExternal(Uri.parse(uri))

telemetry.capture({
Expand Down
6 changes: 3 additions & 3 deletions inlang/source-code/ide-extension/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { errorView } from "./utilities/errors/errors.js"
import { messageView } from "./utilities/messages/messages.js"
import { createFileSystemMapper, type FileSystem } from "./utilities/fs/createFileSystemMapper.js"
import fs from "node:fs/promises"
import { normalizePath } from "@lix-js/fs"
import { gettingStartedView } from "./utilities/getting-started/gettingStarted.js"
import { closestInlangProject } from "./utilities/project/closestInlangProject.js"
import { recommendationBannerView } from "./utilities/recommendation/recommendation.js"
Expand All @@ -20,6 +19,7 @@ import { version } from "../package.json"
import { statusBar } from "./utilities/settings/statusBar.js"
import fg from "fast-glob"
import type { IdeExtensionConfig } from "@inlang/sdk2"
import path from "node:path"
//import { initErrorMonitoring } from "./services/error-monitoring/implementation.js"

// Entry Point
Expand All @@ -46,7 +46,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
},
})

const mappedFs = createFileSystemMapper(normalizePath(workspaceFolder.uri.fsPath), fs)
const mappedFs = createFileSystemMapper(path.normalize(workspaceFolder.uri.fsPath), fs)

await setProjects({ workspaceFolder })
await main({ context, workspaceFolder, fs: mappedFs })
Expand All @@ -66,7 +66,7 @@ async function main(args: {
if (state().projectsInWorkspace.length > 0) {
// find the closest project to the workspace
const closestProjectToWorkspace = await closestInlangProject({
workingDirectory: normalizePath(args.workspaceFolder.uri.fsPath),
workingDirectory: path.normalize(args.workspaceFolder.uri.fsPath),
projects: state().projectsInWorkspace,
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
import { describe, it, expect, vi, beforeEach } from "vitest"
import * as _path from "node:path"
import { createFileSystemMapper } from "./createFileSystemMapper.js"
import { createFileSystemMapper, type FileSystem } from "./createFileSystemMapper.js"

describe("createFileSystemMapper", () => {
const normalizedBase = "/base/path"
let mockFs: FileSystem

beforeEach(() => {
// Mock the fs functions
mockFs = {
// TODO: Fix the type of the mockFs object – fix overloads
writeFile: vi.fn(),
// @ts-expect-error
readFile: vi.fn(),
// @ts-expect-error
readdir: vi.fn(),
rm: vi.fn(),
writeFile: vi.fn(),
mkdir: vi.fn(),
rmdir: vi.fn(),
rm: vi.fn(),
unlink: vi.fn(),
// @ts-expect-error
readdir: vi.fn(),
readlink: vi.fn(),
symlink: vi.fn(),
// @ts-expect-error
mkdir: vi.fn(),
// @ts-expect-error
stat: vi.fn(),
// @ts-expect-error
watch: vi.fn(),
// @ts-expect-error
lstat: vi.fn(),
}
watch: vi.fn(),
access: vi.fn(),
copyFile: vi.fn(),
} as unknown as FileSystem
})

it("should map writeFile correctly", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { normalizePath } from "@lix-js/fs"
import { default as _path } from "node:path"
import type * as fs from "node:fs/promises"

Expand All @@ -13,7 +12,7 @@ export type FileSystem = typeof fs
*/
export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem {
// Prevent path issue on non Unix based system normalizing the <base> before using it
const normalizedBase = normalizePath(base)
const normalizedBase = _path.normalize(base)

return {
// TODO: Those expected typescript errors are because of overloads in node:fs/promises
Expand All @@ -23,7 +22,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem
options: Parameters<FileSystem["readFile"]>[1]
): Promise<string | Uint8Array> => {
return fs.readFile(
normalizePath(
_path.normalize(
String(path).startsWith(normalizedBase)
? String(path)
: _path.resolve(normalizedBase, String(path))
Expand All @@ -37,7 +36,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem
options: Parameters<FileSystem["writeFile"]>[2]
) => {
return fs.writeFile(
normalizePath(
_path.normalize(
String(path).startsWith(normalizedBase)
? String(path)
: _path.resolve(normalizedBase, String(path))
Expand All @@ -52,7 +51,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem
options?: Parameters<FileSystem["mkdir"]>[1]
) => {
return fs.mkdir(
normalizePath(
_path.normalize(
String(path).startsWith(normalizedBase)
? String(path)
: _path.resolve(normalizedBase, String(path))
Expand All @@ -62,7 +61,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem
},
rmdir: async (path: Parameters<FileSystem["rmdir"]>[0]) => {
return fs.rmdir(
normalizePath(
_path.normalize(
String(path).startsWith(normalizedBase)
? String(path)
: _path.resolve(normalizedBase, String(path))
Expand All @@ -71,7 +70,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem
},
rm: async (path: Parameters<FileSystem["rm"]>[0], options: Parameters<FileSystem["rm"]>[1]) => {
return fs.rm(
normalizePath(
_path.normalize(
String(path).startsWith(normalizedBase)
? String(path)
: _path.resolve(normalizedBase, String(path))
Expand All @@ -81,7 +80,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem
},
unlink: async (path: Parameters<FileSystem["unlink"]>[0]) => {
return fs.unlink(
normalizePath(
_path.normalize(
String(path).startsWith(normalizedBase)
? String(path)
: _path.resolve(normalizedBase, String(path))
Expand All @@ -91,7 +90,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem
// @ts-expect-error
readdir: async (path: Parameters<FileSystem["readdir"]>[0]) => {
return fs.readdir(
normalizePath(
_path.normalize(
String(path).startsWith(normalizedBase)
? String(path)
: _path.resolve(normalizedBase, String(path))
Expand All @@ -101,7 +100,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem
// @ts-expect-error
readlink: async (path: Parameters<FileSystem["readlink"]>[0]) => {
return fs.readlink(
normalizePath(
_path.normalize(
String(path).startsWith(normalizedBase)
? String(path)
: _path.resolve(normalizedBase, String(path))
Expand All @@ -113,12 +112,12 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem
target: Parameters<FileSystem["symlink"]>[1]
) => {
return fs.symlink(
normalizePath(
_path.normalize(
String(path).startsWith(normalizedBase)
? String(path)
: _path.resolve(normalizedBase, String(path))
),
normalizePath(
_path.normalize(
String(target).startsWith(normalizedBase)
? String(target)
: _path.resolve(normalizedBase, String(target))
Expand All @@ -128,7 +127,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem
// @ts-expect-error
stat: async (path: Parameters<FileSystem["stat"]>[0]) => {
return fs.stat(
normalizePath(
_path.normalize(
String(path).startsWith(normalizedBase)
? String(path)
: _path.resolve(normalizedBase, String(path))
Expand All @@ -138,7 +137,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem
// @ts-expect-error
lstat: async (path: Parameters<FileSystem["lstat"]>[0]) => {
return fs.lstat(
normalizePath(
_path.normalize(
String(path).startsWith(normalizedBase)
? String(path)
: _path.resolve(normalizedBase, String(path))
Expand All @@ -151,7 +150,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem
options: Parameters<FileSystem["watch"]>[1]
) => {
return fs.watch(
normalizePath(
_path.normalize(
String(path).startsWith(normalizedBase)
? String(path)
: _path.resolve(normalizedBase, String(path))
Expand All @@ -164,7 +163,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem
mode: Parameters<FileSystem["access"]>[1]
) => {
return fs.access(
normalizePath(
_path.normalize(
String(path).startsWith(normalizedBase)
? String(path)
: _path.resolve(normalizedBase, String(path))
Expand All @@ -178,12 +177,12 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem
flags: Parameters<FileSystem["copyFile"]>[2]
) => {
return fs.copyFile(
normalizePath(
_path.normalize(
String(src).startsWith(normalizedBase)
? String(src)
: _path.resolve(normalizedBase, String(src))
),
normalizePath(
_path.normalize(
String(dest).startsWith(normalizedBase)
? String(dest)
: _path.resolve(normalizedBase, String(dest))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as vscode from "vscode"
import { loadProjectInMemory, newProject, saveProjectToDirectory } from "@inlang/sdk2"
import { normalizePath } from "@lix-js/fs"
import fs from "node:fs/promises"
import { createFileSystemMapper } from "../fs/createFileSystemMapper.js"
import path from "node:path"

/**
* Creates a new project in the workspace folder.
Expand All @@ -12,10 +12,10 @@ import { createFileSystemMapper } from "../fs/createFileSystemMapper.js"
export async function createNewProjectHandler(args: { workspaceFolderPath: string }) {
try {
const workspaceFolderPath = args.workspaceFolderPath
const nodeishFs = createFileSystemMapper(normalizePath(workspaceFolderPath), fs)
const nodeishFs = createFileSystemMapper(path.normalize(workspaceFolderPath), fs)

// The path to the project directory
const projectPath = normalizePath(`${workspaceFolderPath}/project.inlang`)
const projectPath = path.normalize(`${workspaceFolderPath}/project.inlang`)

// Create a new project in memory
const project = await loadProjectInMemory({
Expand All @@ -33,6 +33,5 @@ export async function createNewProjectHandler(args: { workspaceFolderPath: strin
vscode.commands.executeCommand("workbench.action.reloadWindow")
} catch (error: any) {
vscode.window.showErrorMessage(`Failed to create new project: ${error.message}`)
console.log(error)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ export async function createMessageHtml(args: {
? `<span title="Jump to message" onclick="${jumpCommand}"><span class="codicon codicon-magnet"></span></span>`
: ""
}
<span title="Open in Fink" onclick="${openCommand}"><span class="codicon codicon-link-external"></span></span>
<!-- Removed until we have a proper way to open in Fink with Lix host -->
<!--<span title="Open in Fink" onclick="${openCommand}"><span class="codicon codicon-link-external"></span></span>-->
</div>
</div>
<div class="content" style="display: none;">
Expand Down
Loading
Loading