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

[quick-edit] Typescript support through JSDoc #3043

Merged
merged 2 commits into from
Apr 14, 2023
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,4 @@ packages/quick-edit/web

# VSCode Theme
*.vsix
./vendor/vscode
vendor/vscode
39 changes: 31 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions packages/quick-edit-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"publisher": "cloudflare",
"browser": "./dist/extension.js",
"scripts": {
"package-web": "esbuild --bundle --external:vscode --format=cjs src/extension.ts --outfile=dist/extension.js",
"package-web": "node -r esbuild-register scripts/bundle.ts",
"vscode:prepublish": "npm run package-web",
"watch-web": "npm run package-web -- --watch"
},
Expand Down Expand Up @@ -40,7 +40,9 @@
"onFileSystem:cfs"
],
"devDependencies": {
"esbuild": "^0.17.11",
"@cloudflare/workers-types": "^4.20230404.0",
"esbuild": "0.16.3",
"esbuild-register": "^3.4.2",
"typescript": "^4.9.5"
},
"engines": {
Expand Down
61 changes: 61 additions & 0 deletions packages/quick-edit-extension/scripts/bundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { readFile } from "fs/promises";
import * as esbuild from "esbuild";

type BuildFlags = {
watch?: boolean;
};

async function buildMain(flags: BuildFlags = {}) {
const options: esbuild.BuildOptions = {
entryPoints: ["./src/extension.ts"],
bundle: true,
outfile: "./dist/extension.js",
format: "cjs",
external: ["vscode"],
logLevel: "info",
plugins: [
{
name: "workers-types",
setup(build) {
build.onResolve({ filter: /^raw:.*/ }, async (args) => {
const result = await build.resolve(args.path.slice(4), {
kind: "import-statement",
resolveDir: args.resolveDir,
});
return {
path: result.path,
namespace: "raw-file",
};
});

build.onLoad(
{ filter: /.*/, namespace: "raw-file" },
async (args) => {
const contents = await readFile(args.path);
return { contents, loader: "text" };
}
);
},
},
],
};
if (flags.watch) {
const ctx = await esbuild.context(options);
await ctx.watch();
} else {
await esbuild.build(options);
}
}

async function run() {
await buildMain();
if (process.argv.includes("--watch")) {
console.log("Built. Watching for changes...");
await Promise.all([buildMain({ watch: true })]);
}
}

run().catch((e) => {
console.error(e);
process.exit(1);
});
9 changes: 9 additions & 0 deletions packages/quick-edit-extension/scripts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"module": "CommonJS",
"types": ["node"]
},
"include": ["bundle.ts"],
"exclude": []
}
69 changes: 68 additions & 1 deletion packages/quick-edit-extension/src/cfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import workersTypes from "raw:@cloudflare/workers-types/index.d.ts";
import {
Disposable,
EventEmitter,
Expand All @@ -14,6 +15,7 @@ import {
Range,
Uri,
workspace,
FilePermission,
} from "vscode";
import type { Channel, FromQuickEditMessage, ToQuickEditMessage } from "./ipc";
import type { WorkerLoadedMessage } from "./ipc";
Expand Down Expand Up @@ -43,6 +45,7 @@ export class File implements FileStat {

name: string;
data?: Uint8Array;
permissions?: FilePermission;

constructor(public uri: Uri, name: string) {
this.type = FileType.File;
Expand All @@ -51,6 +54,9 @@ export class File implements FileStat {
this.size = 0;
this.name = name;
}
public setReadOnly() {
this.permissions = FilePermission.Readonly;
}
}

export class Directory implements FileStat {
Expand All @@ -73,7 +79,7 @@ export class Directory implements FileStat {
}

export type Entry = File | Directory;

const encoder = new TextEncoder();
export class CFS
implements
FileSystemProvider,
Expand Down Expand Up @@ -108,6 +114,63 @@ export class CFS
async seed(files: WorkerLoadedMessage["body"]) {
this.rootFolder = files.name ?? this.rootFolder;
this.createDirectory(Uri.parse(`cfs:/${this.rootFolder}/`));
this.writeFile(
mrbbot marked this conversation as resolved.
Show resolved Hide resolved
Uri.parse(`cfs:/${this.rootFolder}/jsconfig.json`),
encoder.encode(
`
{
"compilerOptions": {
"module": "ESNext",
"target": "ES2020",
"checkJs": true,
"allowJs": true,
"types": [],
"lib": ["ES2020"]
}
}
`.trim()
),
{
create: true,
overwrite: true,
readOnly: true,
suppressChannelUpdate: true,
}
);
this.writeFile(
Uri.parse(`cfs:/${this.rootFolder}/workers-types.d.ts`),
encoder.encode(
`
${workersTypes}
declare module "*.wasm" {
const value: WebAssembly.Module;
export default value;
}

declare module "*.html" {
const value: string;
export default value;
}

declare module "*.txt" {
const value: string;
export default value;
}

declare module "*.bin" {
const value: ArrayBuffer;
export default value;
}
`.trim()
),
{
create: true,
overwrite: true,
readOnly: true,
suppressChannelUpdate: true,
}
);

for (const { path, contents } of files.files) {
const pathSegments = path.split("/");
if (pathSegments.length > 1) {
Expand Down Expand Up @@ -168,6 +231,7 @@ export class CFS
create: boolean;
overwrite: boolean;
suppressChannelUpdate?: boolean;
readOnly?: boolean;
}
): void {
const basename = this._basename(uri.path);
Expand Down Expand Up @@ -198,6 +262,9 @@ export class CFS
entry.mtime = Date.now();
entry.size = content.byteLength;
entry.data = content;
if (options.readOnly) {
entry.setReadOnly();
penalosa marked this conversation as resolved.
Show resolved Hide resolved
}
if (!options.suppressChannelUpdate)
this.channel.postMessage({
type: "UpdateFile",
Expand Down
4 changes: 4 additions & 0 deletions packages/quick-edit-extension/src/raw.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "raw:*" {
const value: string;
export default value;
}
3 changes: 2 additions & 1 deletion packages/quick-edit-extension/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"sourceMap": true,
"rootDir": "src",
"strict": true
}
},
"exclude": ["scripts"]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 1d978b85556fde86dfec9ed1455e35c9b587ba95 Mon Sep 17 00:00:00 2001
From 6849aafb8c1311b367431cbf6054a531abed2134 Mon Sep 17 00:00:00 2001
From: Samuel Macleod <smacleod@cloudflare.com>
Date: Mon, 3 Apr 2023 11:18:10 +0100
Subject: [PATCH 01/10] Add Custom workbench for Cloudflare
Subject: [PATCH 01/11] Add Custom workbench for Cloudflare

---
src/vs/code/browser/workbench/workbench.ts | 522 +++------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 69a4c2e499a1e9ba99c2ea819b41af7abfb4053e Mon Sep 17 00:00:00 2001
From 6c409326aafb7a6ad7a755f642468e15f05dd4f2 Mon Sep 17 00:00:00 2001
From: Jacob M-G Evans <jacobmgevans@gmail.com>
Date: Fri, 31 Mar 2023 17:11:08 -0500
Subject: [PATCH 02/10] Remove Themes from Setting SubMenu
Subject: [PATCH 02/11] Remove Themes from Setting SubMenu

---
.../themes/browser/themes.contribution.ts | 76 +++++++++----------
Expand Down
4 changes: 2 additions & 2 deletions packages/quick-edit/patches/0003-Removed-Menu.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From ca3fff3caa78e54bee3503f985dd84800632239b Mon Sep 17 00:00:00 2001
From d779d203de3f456a7b3c7f1674ec67403e40cfa2 Mon Sep 17 00:00:00 2001
From: Jacob M-G Evans <jacobmgevans@gmail.com>
Date: Tue, 28 Mar 2023 14:41:00 -0500
Subject: [PATCH 03/10] Removed Menu
Subject: [PATCH 03/11] Removed Menu

---
.../browser/parts/titlebar/menubarControl.ts | 94 +++++++++----------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 6434055430af0c2789affd2296900fefc0765d2c Mon Sep 17 00:00:00 2001
From a0f0970d77717bb6715de290e08720f50693a39c Mon Sep 17 00:00:00 2001
From: Jacob M-G Evans <jacobmgevans@gmail.com>
Date: Fri, 31 Mar 2023 17:11:28 -0500
Subject: [PATCH 04/10] Remove Profile from Setting SubMenu
Subject: [PATCH 04/11] Remove Profile from Setting SubMenu

---
.../browser/userDataProfile.ts | 46 +++++++++----------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 123d396902358d75908af3a360c75950763b413f Mon Sep 17 00:00:00 2001
From a532ef3f3e5630c3c139ef377eec4d2d9d65a0fb Mon Sep 17 00:00:00 2001
From: Jacob M-G Evans <jacobmgevans@gmail.com>
Date: Tue, 28 Mar 2023 14:53:02 -0500
Subject: [PATCH 05/10] Remove Account & Extension
Subject: [PATCH 05/11] Remove Account & Extension

---
.../parts/activitybar/activitybarPart.ts | 26 +++++++++----------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From e49ad7c980d22439853c75c7e2c1c55a007c556f Mon Sep 17 00:00:00 2001
From 098049536be307fae8309d0f48e1ff92c19c1abd Mon Sep 17 00:00:00 2001
From: Jacob M-G Evans <jacobmgevans@gmail.com>
Date: Fri, 31 Mar 2023 17:08:40 -0500
Subject: [PATCH 06/10] Remove Debug Icon & other default views
Subject: [PATCH 06/11] Remove Debug Icon & other default views

---
.../debug/browser/debug.contribution.ts | 46 +++++++++----------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From bdc5b0d280c565e2ac586f83ac1f8ad67bcd2770 Mon Sep 17 00:00:00 2001
From 2138039ca5b9a35f1abefb723118c89758179ebf Mon Sep 17 00:00:00 2001
From: Jacob M-G Evans <jacobmgevans@gmail.com>
Date: Tue, 28 Mar 2023 14:42:09 -0500
Subject: [PATCH 07/10] Remove Source Control
Subject: [PATCH 07/11] Remove Source Control

---
.../contrib/scm/browser/scm.contribution.ts | 100 +++++++++---------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 4ff93c1ca04ac255866ccb3688177d31a13af590 Mon Sep 17 00:00:00 2001
From 3b5d5f2f949840d45d8ff29db9d219dc3b6d22c6 Mon Sep 17 00:00:00 2001
From: Jacob M-G Evans <jacobmgevans@gmail.com>
Date: Fri, 31 Mar 2023 17:07:44 -0500
Subject: [PATCH 08/10] Remove 'Custom' Menu (hamburger)
Subject: [PATCH 08/11] Remove 'Custom' Menu (hamburger)

---
.../parts/activitybar/activitybarPart.ts | 6 +-
Expand Down
Loading