Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 30 additions & 22 deletions editors/code/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ import {DeployedContract} from "./common/types/contract"
let client: LanguageClient | undefined = undefined
let cachedToolchainInfo: SetToolchainVersionParams | undefined = undefined

function getVersionSourceLabel(params: SetToolchainVersionParams): string {
return params.version.source === "acton" ? "Acton project" : "Configured toolchain"
}

export async function activate(context: vscode.ExtensionContext): Promise<void> {
await checkConflictingExtensions()

Expand Down Expand Up @@ -371,6 +375,7 @@ async function startServer(context: vscode.ExtensionContext): Promise<vscode.Dis
cachedToolchainInfo = params

const settings = vscode.workspace.getConfiguration("ton")
const versionSource = getVersionSourceLabel(params)
const hash =
settings.get<boolean>("tolk.toolchain.showShortCommitInStatusBar") &&
params.version.commit.length > 8
Expand All @@ -387,12 +392,12 @@ async function startServer(context: vscode.ExtensionContext): Promise<vscode.Dis
langStatusBar.text = `Tolk ${params.version.number}${hash}`

const tooltipLines = [
`**Tolk Toolchain Information**`,
`**Tolk Environment Information**`,
``,
`**Version:** ${params.version.number}`,
`**Version Source:** ${versionSource}`,
``,
`**Commit:** ${params.version.commit || "Unknown"}`,
``,
...(params.version.commit ? [`**Commit:** ${params.version.commit}`, ``] : []),
`**Active Toolchain:** ${activeToolchainName} (${activeToolchainId})`,
``,
`**Toolchain:**`,
Expand Down Expand Up @@ -465,7 +470,9 @@ function registerCommands(disposables: vscode.Disposable[]): void {
disposables.push(
vscode.commands.registerCommand("tolk.showToolchainInfo", async () => {
if (!cachedToolchainInfo) {
vscode.window.showInformationMessage("Toolchain information not available")
vscode.window.showInformationMessage(
"Tolk environment information is not available",
)
return
}

Expand All @@ -481,10 +488,8 @@ function registerCommands(disposables: vscode.Disposable[]): void {
const items = [
{
label: "$(info) Version Information",
detail: `Tolk ${info.version.number}`,
description: info.version.commit
? `Commit: ${info.version.commit}`
: "No commit info",
detail: `Tolk ${info.version.number} (${getVersionSourceLabel(info)})`,
description: info.version.commit ? `Commit: ${info.version.commit}` : undefined,
},
{
label: "$(tools) Active Toolchain",
Expand Down Expand Up @@ -519,7 +524,7 @@ function registerCommands(disposables: vscode.Disposable[]): void {
]

const selected = await vscode.window.showQuickPick(items, {
placeHolder: "Tolk Toolchain Information",
placeHolder: "Tolk Environment Information",
canPickMany: false,
})

Expand All @@ -534,20 +539,23 @@ function registerCommands(disposables: vscode.Disposable[]): void {
break
}
case "copy": {
const clipboardText = `Tolk Toolchain Information:
Version: ${info.version.number}
Commit: ${info.version.commit || "Unknown"}
Active Toolchain: ${activeToolchainName} (${activeToolchainId})
Path: ${info.toolchain.path}
Auto-detected: ${info.toolchain.isAutoDetected}
Detection method: ${info.toolchain.detectionMethod ?? "Unknown"}
Platform: ${info.environment.platform}
Architecture: ${info.environment.arch}
Node.js: ${info.environment.nodeVersion ?? "Unknown"}`

await vscode.env.clipboard.writeText(clipboardText)
const clipboardLines = [
"Tolk Environment Information:",
`Version: ${info.version.number}`,
`Version Source: ${getVersionSourceLabel(info)}`,
...(info.version.commit ? [`Commit: ${info.version.commit}`] : []),
`Active Toolchain: ${activeToolchainName} (${activeToolchainId})`,
`Path: ${info.toolchain.path}`,
`Auto-detected: ${info.toolchain.isAutoDetected}`,
`Detection method: ${info.toolchain.detectionMethod ?? "Unknown"}`,
`Platform: ${info.environment.platform}`,
`Architecture: ${info.environment.arch}`,
`Node.js: ${info.environment.nodeVersion ?? "Unknown"}`,
]

await vscode.env.clipboard.writeText(clipboardLines.join("\n"))
vscode.window.showInformationMessage(
"Toolchain information copied to clipboard",
"Tolk environment information copied to clipboard",
)
break
}
Expand Down
98 changes: 98 additions & 0 deletions server/src/acton/ActonTolkVersion.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// SPDX-License-Identifier: MIT
// Copyright © 2026 TON Core

jest.mock("node:child_process", () => ({
...jest.requireActual<typeof import("node:child_process")>("node:child_process"),
spawnSync: jest.fn(),
}))

import * as cp from "node:child_process"
import * as fs from "node:fs"
import * as os from "node:os"
import * as path from "node:path"

import {parseActonDoctorTolkVersion, resolveDisplayedTolkVersion} from "./ActonTolkVersion"

describe("Acton Tolk version resolution", () => {
const tempDirs: string[] = []

afterEach(() => {
jest.restoreAllMocks()

for (const dir of tempDirs.splice(0)) {
fs.rmSync(dir, {recursive: true, force: true})
}
})

it("parses the native Tolk version from acton doctor output", () => {
const output = `
Native Libraries
tolk.load_ok: true
tolk.version: 1.3.0
tolk.ton_commit_hash: dbf120b4d57e557a1602a95b5848e65ffc430094
`

expect(parseActonDoctorTolkVersion(output)).toBe("1.3.0")
})

it("ignores missing or unavailable Acton Tolk versions", () => {
const output = `
Native Libraries
tolk.load_ok: false
tolk.version: <n/a>
`

expect(parseActonDoctorTolkVersion(output)).toBeNull()
})

it("prefers the Acton-managed Tolk version when Acton.toml is present", () => {
const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "acton-tolk-version-"))
tempDirs.push(projectDir)
fs.writeFileSync(path.join(projectDir, "Acton.toml"), "")

const mockedSpawnSync = cp.spawnSync as jest.MockedFunction<typeof cp.spawnSync>
mockedSpawnSync.mockReturnValue({
pid: 1,
output: [null, "tolk.load_ok: true\ntolk.version: 1.3.0\n", ""],
stdout: "tolk.load_ok: true\ntolk.version: 1.3.0\n",
stderr: "",
status: 0,
signal: null,
} as cp.SpawnSyncReturns<string>)

expect(
resolveDisplayedTolkVersion(
projectDir,
{
number: "0.9.0",
commit: "deadbeef",
},
"acton",
),
).toEqual({
number: "1.3.0",
commit: "",
source: "acton",
})
})

it("falls back to the configured toolchain version outside Acton projects", () => {
const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "acton-tolk-version-"))
tempDirs.push(projectDir)

expect(
resolveDisplayedTolkVersion(
projectDir,
{
number: "0.9.0",
commit: "deadbeef",
},
"acton",
),
).toEqual({
number: "0.9.0",
commit: "deadbeef",
source: "toolchain",
})
})
})
109 changes: 109 additions & 0 deletions server/src/acton/ActonTolkVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// SPDX-License-Identifier: MIT
// Copyright © 2026 TON Core

import * as cp from "node:child_process"
import * as fs from "node:fs"
import * as os from "node:os"
import * as path from "node:path"

import {TolkVersionInfo} from "@shared/shared-msgtypes"

interface BasicTolkVersionInfo {
readonly number: string
readonly commit: string
}

export function resolveDisplayedTolkVersion(
projectRoot: string,
toolchainVersion: BasicTolkVersionInfo,
actonPath: string,
): TolkVersionInfo {
const actonVersion = resolveActonProjectTolkVersion(projectRoot, actonPath)
if (actonVersion) {
return actonVersion
}

return {
...toolchainVersion,
source: "toolchain",
}
}

export function parseActonDoctorTolkVersion(output: string): string | null {
const fields = parseActonDoctorFields(output)
const loadOk = fields.get("tolk.load_ok")
const version = fields.get("tolk.version")?.trim()

if (loadOk === "false") {
return null
}

if (!version || version.startsWith("<")) {
return null
}

return version
}

function resolveActonProjectTolkVersion(
projectRoot: string,
actonPath: string,
): TolkVersionInfo | null {
const manifestPath = path.join(projectRoot, "Acton.toml")
if (!fs.existsSync(manifestPath)) {
return null
}

const resolvedActonPath = actonPath.trim() === "" ? "acton" : actonPath

try {
const result = cp.spawnSync(
resolvedActonPath,
["doctor", "--manifest-path", manifestPath],
{
encoding: "utf8",
env: {
...process.env,
ACTON_LOG_DIR: process.env.ACTON_LOG_DIR ?? os.tmpdir(),
},
maxBuffer: 10 * 1024 * 1024,
timeout: 5000,
windowsHide: true,
},
)

if (result.error || result.status !== 0) {
return null
}

const version = parseActonDoctorTolkVersion(`${result.stdout}\n${result.stderr}`)
if (!version) {
return null
}

return {
number: version,
commit: "",
source: "acton",
}
} catch {
return null
}
}

function parseActonDoctorFields(output: string): Map<string, string> {
const fields: Map<string, string> = new Map()

for (const rawLine of output.split(/\r?\n/u)) {
const line = rawLine.trim()
const match = /^([a-z0-9_.-]+):\s+(.*)$/iu.exec(line)
if (!match) {
continue
}

const [, key, value] = match
fields.set(key, value.trim())
}

return fields
}
Loading
Loading