diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..072deab1 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,6 @@ +root = true + +[*] +indent_style = space +trim_trailing_whitespace = true +indent_size = 2 \ No newline at end of file diff --git a/ci/build.ts b/ci/build.ts index f5cbbd68..0628f492 100644 --- a/ci/build.ts +++ b/ci/build.ts @@ -174,7 +174,7 @@ class Builder { await this.copyDependencies("code-server", this.rootPath, this.buildPath, { commit, - version: process.env.VERSION, + version: this.codeServerVersion, }) } @@ -204,13 +204,17 @@ class Builder { const vscodeBuildPath = path.join(this.buildPath, "lib/vscode") await this.task("copying vs code into build directory", async () => { - await fs.mkdirp(vscodeBuildPath) + await fs.mkdirp(path.join(vscodeBuildPath, "resources/linux")) await Promise.all([ fs.move( path.join(this.vscodeSourcePath, `out-vscode${process.env.MINIFY ? "-min" : ""}`), path.join(vscodeBuildPath, "out"), ), fs.copy(path.join(this.vscodeSourcePath, ".build/extensions"), path.join(vscodeBuildPath, "extensions")), + fs.copy( + path.join(this.vscodeSourcePath, "resources/linux/code.png"), + path.join(vscodeBuildPath, "resources/linux/code.png"), + ), ]) }) @@ -256,6 +260,38 @@ class Builder { * Bundles the built code into a binary. */ private async binary(binaryName: string): Promise { + // Prepend code to the target which enables finding files within the binary. + const prependLoader = async (relativeFilePath: string): Promise => { + const filePath = path.join(this.buildPath, relativeFilePath) + const shim = ` + if (!global.NBIN_LOADED) { + try { + const nbin = require("nbin"); + nbin.shimNativeFs("${this.buildPath}"); + global.NBIN_LOADED = true; + const path = require("path"); + const rg = require("vscode-ripgrep"); + rg.binaryRgPath = rg.rgPath; + rg.rgPath = path.join(require("os").tmpdir(), "code-server", path.basename(rg.binaryRgPath)); + } catch (error) { /* Not in the binary. */ } + } + ` + const content = await fs.readFile(filePath, "utf8") + if (!content.startsWith(shim)) { + await fs.writeFile(filePath, shim + content) + } + } + + await this.task("Prepending nbin loader", () => { + return Promise.all([ + prependLoader("out/node/entry.js"), + prependLoader("lib/vscode/out/vs/server/entry.js"), + prependLoader("lib/vscode/out/vs/server/fork.js"), + prependLoader("lib/vscode/out/bootstrap-fork.js"), + prependLoader("lib/vscode/extensions/node_modules/typescript/lib/tsserver.js"), + ]) + }) + const bin = new Binary({ mainFile: path.join(this.buildPath, "out/node/entry.js"), target: await this.target(), diff --git a/src/browser/pages/home.css b/src/browser/pages/home.css index 018623ba..b20dbce5 100644 --- a/src/browser/pages/home.css +++ b/src/browser/pages/home.css @@ -46,6 +46,7 @@ .block-row > .item > .icon { height: 1rem; margin-right: 5px; + vertical-align: top; width: 1rem; } diff --git a/src/browser/pages/home.html b/src/browser/pages/home.html index e210673b..a6aa8db9 100644 --- a/src/browser/pages/home.html +++ b/src/browser/pages/home.html @@ -21,25 +21,36 @@
+ + + + + +
-

Running Applications

- {{APP_LIST:RUNNING}} +

Launch

+
-

Update

+

Version

{{UPDATE:NAME}}
-
-

Editors

- {{APP_LIST:EDITORS}} -
+ + + + -
-

Other

- {{APP_LIST:OTHER}} -
+ + + +
diff --git a/src/node/app/bin.ts b/src/node/app/bin.ts index 2fa397e1..4cf57c73 100644 --- a/src/node/app/bin.ts +++ b/src/node/app/bin.ts @@ -11,6 +11,7 @@ const getVscodeVersion = (): string => { export const Vscode: Application = { categories: ["Editor"], + installed: true, name: "VS Code", path: "/vscode", version: getVscodeVersion(), @@ -23,5 +24,5 @@ export const findApplications = async (): Promise> => } export const findWhitelistedApplications = async (): Promise> => { - return [] + return [Vscode] } diff --git a/src/node/app/vscode.ts b/src/node/app/vscode.ts index 243f701d..2f1132e0 100644 --- a/src/node/app/vscode.ts +++ b/src/node/app/vscode.ts @@ -35,10 +35,10 @@ export class VscodeHttpProvider extends HttpProvider { const id = generateUuid() const vscode = await this.fork() - logger.debug("Setting up VS Code...") + logger.debug("setting up vs code...") return new Promise((resolve, reject) => { vscode.once("message", (message: VscodeMessage) => { - logger.debug("Got message from VS Code", field("message", message)) + logger.debug("got message from vs code", field("message", message)) return message.type === "options" && message.id === id ? resolve(message.options) : reject(new Error("Unexpected response during initialization")) @@ -51,7 +51,7 @@ export class VscodeHttpProvider extends HttpProvider { private fork(): Promise { if (!this._vscode) { - logger.debug("Forking VS Code...") + logger.debug("forking vs code...") const vscode = cp.fork(path.join(this.serverRootPath, "fork")) vscode.on("error", (error) => { logger.error(error.message) @@ -64,7 +64,7 @@ export class VscodeHttpProvider extends HttpProvider { this._vscode = new Promise((resolve, reject) => { vscode.once("message", (message: VscodeMessage) => { - logger.debug("Got message from VS Code", field("message", message)) + logger.debug("got message from vs code", field("message", message)) return message.type === "ready" ? resolve(vscode) : reject(new Error("Unexpected response waiting for ready response")) diff --git a/src/node/cli.ts b/src/node/cli.ts index 4389c876..072495c3 100644 --- a/src/node/cli.ts +++ b/src/node/cli.ts @@ -198,16 +198,17 @@ export const parse = (argv: string[]): Args => { logger.debug("parsed command line", field("args", args)) - if (process.env.LOG_LEVEL === "trace" || args.verbose) { + // Ensure the environment variable and the flag are synced up. The flag takes + // priority over the environment variable. + if (args.log === "trace" || process.env.LOG_LEVEL === "trace" || args.verbose) { + args.log = process.env.LOG_LEVEL = "trace" args.verbose = true - args.log = "trace" - } else if (!args.log) { + } else if (!args.log && process.env.LOG_LEVEL) { args.log = process.env.LOG_LEVEL + } else if (args.log) { + process.env.LOG_LEVEL = args.log } - // Ensure this passes down to forked processes. - process.env.LOG_LEVEL = args.log - switch (args.log) { case "trace": logger.level = Level.Trace diff --git a/src/node/entry.ts b/src/node/entry.ts index f64606de..e16f8067 100644 --- a/src/node/entry.ts +++ b/src/node/entry.ts @@ -110,7 +110,7 @@ if (args.help) { process.exit(0) } else if (args["list-extensions"] || args["install-extension"] || args["uninstall-extension"]) { process.env.NBIN_BYPASS = "true" - logger.debug("Forking VS Code CLI...") + logger.debug("forking vs code cli...") const vscode = cp.fork(path.resolve(__dirname, "../../lib/vscode/out/vs/server/fork"), [], { env: { ...process.env, diff --git a/test/cli.test.ts b/test/cli.test.ts index cf2acb34..04fcd771 100644 --- a/test/cli.test.ts +++ b/test/cli.test.ts @@ -4,6 +4,10 @@ import { parse } from "../src/node/cli" import { xdgLocalDir } from "../src/node/util" describe("cli", () => { + beforeEach(() => { + delete process.env.LOG_LEVEL + }) + it("should set defaults", () => { assert.deepEqual(parse([]), { _: [], @@ -86,6 +90,29 @@ describe("cli", () => { verbose: true, version: true, }) + assert.equal(process.env.LOG_LEVEL, "trace") + }) + + it("should use log level env var", () => { + process.env.LOG_LEVEL = "debug" + assert.deepEqual(parse([]), { + _: [], + "extensions-dir": path.join(xdgLocalDir, "extensions"), + "user-data-dir": xdgLocalDir, + log: "debug", + }) + assert.equal(process.env.LOG_LEVEL, "debug") + }) + + it("should prefer --log to env var", () => { + process.env.LOG_LEVEL = "debug" + assert.deepEqual(parse(["--log", "info"]), { + _: [], + "extensions-dir": path.join(xdgLocalDir, "extensions"), + "user-data-dir": xdgLocalDir, + log: "info", + }) + assert.equal(process.env.LOG_LEVEL, "info") }) it("should error if value isn't provided", () => {