Skip to content

Commit

Permalink
codercom updates (#1)
Browse files Browse the repository at this point in the history
* Add --socket flag (coder#564)

* Add --socket flag

* Add msg for already bound socket

* Bundle grammars (coder#563)

* Fix clipboard pasting

* Remove log statement from copy

* Offer https/http url based on schema (coder#572)

* Let people know when telemetry is disabled, change url to https if secure connection

* Remove --no-auth as a http candidate

* Rename variable, change let to const

* Fix no-auth to still use HTTPS, set default for no-auth to false (coder#573)

* Fix markdown preview focus (coder#546)

* Fix hash

* Remove whitespace
  • Loading branch information
kylejeske authored Apr 24, 2019
1 parent 5f40ebb commit a0cc5d7
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 19 deletions.
22 changes: 18 additions & 4 deletions packages/server/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ commander.version(process.env.VERSION || "development")
.option("-h, --host <value>", "Customize the hostname.", "0.0.0.0")
.option("-o, --open", "Open in the browser on startup.", false)
.option("-p, --port <number>", "Port to bind on.", parseInt(process.env.PORT!, 10) || 8443)
.option("-N, --no-auth", "Start without requiring authentication.", undefined)
.option("-N, --no-auth", "Start without requiring authentication.", false)
.option("-H, --allow-http", "Allow http connections.", false)
.option("-P, --password <value>", "DEPRECATED: Use the PASSWORD environment variable instead. Specify a password for authentication.")
.option("--disable-telemetry", "Disables ALL telemetry.", false)
.option("--socket <value>", "Listen on a UNIX socket. Host and port will be ignored when set.")
.option("--install-extension <value>", "Install an extension by its ID.")
.option("--bootstrap-fork <name>", "Used for development. Never set.")
.option("--extra-args <args>", "Used for development. Never set.")
Expand Down Expand Up @@ -63,6 +64,7 @@ const bold = (text: string | number): string | number => {
readonly open?: boolean;
readonly cert?: string;
readonly certKey?: string;
readonly socket?: string;

readonly installExtension?: string;

Expand Down Expand Up @@ -267,7 +269,11 @@ const bold = (text: string | number): string | number => {
});

logger.info("Starting webserver...", field("host", options.host), field("port", options.port));
app.server.listen(options.port, options.host);
if (options.socket) {
app.server.listen(options.socket);
} else {
app.server.listen(options.port, options.host);
}
let clientId = 1;
app.wss.on("connection", (ws, req) => {
const id = clientId++;
Expand All @@ -284,7 +290,11 @@ const bold = (text: string | number): string | number => {
});
app.wss.on("error", (err: NodeJS.ErrnoException) => {
if (err.code === "EADDRINUSE") {
logger.error(`Port ${bold(options.port)} is in use. Please free up port ${options.port} or specify a different port with the -p flag`);
if (options.socket) {
logger.error(`Socket ${bold(options.socket)} is in use. Please specify a different socket.`);
} else {
logger.error(`Port ${bold(options.port)} is in use. Please free up port ${options.port} or specify a different port with the -p flag`);
}
process.exit(1);
}
});
Expand All @@ -300,8 +310,12 @@ const bold = (text: string | number): string | number => {
} else {
logger.warn("Launched without authentication.");
}
if (options.disableTelemetry) {
logger.info("Telemetry is disabled");
}

const url = `http://localhost:${options.port}/`;
const protocol = options.allowHttp ? "http" : "https";
const url = `${protocol}://localhost:${options.port}/`;
logger.info(" ");
logger.info("Started (click the link below to open):");
logger.info(url);
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const createApp = async (options: CreateAppOptions): Promise<{
});
});

const server = httpolyglot.createServer(options.bypassAuth ? {} : options.httpsOptions || certs, app) as http.Server;
const server = httpolyglot.createServer(options.allowHttp ? {} : options.httpsOptions || certs, app) as http.Server;
const wss = new ws.Server({ server });

wss.shouldHandle = (req): boolean => {
Expand Down
18 changes: 18 additions & 0 deletions packages/vscode/src/fill/vscodeTextmate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ import * as vscodeTextmate from "../../../../lib/vscode/node_modules/vscode-text

const target = vscodeTextmate as typeof vscodeTextmate;

const ctx = (require as any).context("../../../../lib/extensions", true, /.*\.tmLanguage.json$/);
// Maps grammar scope to loaded grammar
const scopeToGrammar = {} as any;

ctx.keys().forEach((key: string) => {
const value = ctx(key);
if (value.scopeName) {
scopeToGrammar[value.scopeName] = value;
}
});

target.Registry = class Registry extends vscodeTextmate.Registry {
public constructor(opts: vscodeTextmate.RegistryOptions) {
super({
Expand All @@ -21,6 +32,13 @@ target.Registry = class Registry extends vscodeTextmate.Registry {
}).catch(reason => rej(reason));
});
},
loadGrammar: async (scopeName: string) => {
if (scopeToGrammar[scopeName]) {
return scopeToGrammar[scopeName];
}

return opts.loadGrammar(scopeName);
},
});
}
};
Expand Down
53 changes: 39 additions & 14 deletions scripts/vscode.patch
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ index 1f8b17a..2a875f9 100644
+ await cli.main(args);
+ return; // Always just do this for now.
diff --git a/src/vs/editor/browser/config/configuration.ts b/src/vs/editor/browser/config/configuration.ts
index f97a692..0206957 100644
index f97a692..8059a67 100644
--- a/src/vs/editor/browser/config/configuration.ts
+++ b/src/vs/editor/browser/config/configuration.ts
@@ -10 +9,0 @@ import { Disposable } from 'vs/base/common/lifecycle';
Expand All @@ -187,9 +187,6 @@ index f97a692..0206957 100644
@@ -367 +366 @@ export class Configuration extends CommonEditorConfiguration {
- if (platform.isMacintosh) {
+ if (browser.isMacintosh) {
@@ -378 +377 @@ export class Configuration extends CommonEditorConfiguration {
- emptySelectionClipboard: browser.isWebKit || browser.isFirefox,
+ emptySelectionClipboard: false, // browser.isWebKit || browser.isFirefox,
diff --git a/src/vs/editor/browser/controller/mouseHandler.ts b/src/vs/editor/browser/controller/mouseHandler.ts
index b3b4472..f888d63 100644
--- a/src/vs/editor/browser/controller/mouseHandler.ts
Expand Down Expand Up @@ -250,32 +247,55 @@ index c69ea3f..b8d87f7 100644
-const GOLDEN_LINE_HEIGHT_RATIO = platform.isMacintosh ? 1.5 : 1.35;
+const GOLDEN_LINE_HEIGHT_RATIO = browser.isMacintosh ? 1.5 : 1.35;
diff --git a/src/vs/editor/contrib/clipboard/clipboard.ts b/src/vs/editor/contrib/clipboard/clipboard.ts
index 990be3a..8a326c6 100644
index 990be3a..18ae0d5 100644
--- a/src/vs/editor/contrib/clipboard/clipboard.ts
+++ b/src/vs/editor/contrib/clipboard/clipboard.ts
@@ -29 +29,2 @@ const supportsCopyWithSyntaxHighlighting = (supportsCopy && !browser.isEdgeOrIE)
@@ -18,0 +19 @@ import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegis
+import { clipboard } from 'electron';
@@ -29 +30,2 @@ const supportsCopyWithSyntaxHighlighting = (supportsCopy && !browser.isEdgeOrIE)
-const supportsPaste = (platform.isNative || (!browser.isChrome && document.queryCommandSupported('paste')));
+// const supportsPaste = (platform.isNative || (!browser.isChrome && document.queryCommandSupported('paste')));
+const supportsPaste = true;
@@ -176,0 +178 @@ class ExecCommandPasteAction extends ExecCommandAction {
@@ -71 +73 @@ class ExecCommandCutAction extends ExecCommandAction {
- kbOpts = null;
+ // kbOpts = null;
@@ -119 +121 @@ class ExecCommandCopyAction extends ExecCommandAction {
- kbOpts = null;
+ // kbOpts = null;
@@ -174 +176 @@ class ExecCommandPasteAction extends ExecCommandAction {
- kbOpts = null;
+ // kbOpts = null;
@@ -176,0 +179 @@ class ExecCommandPasteAction extends ExecCommandAction {
+ const { workbench } = require('vs/../../../../packages/vscode/src/workbench') as typeof import ('vs/../../../../packages/vscode/src/workbench');
@@ -181 +183 @@ class ExecCommandPasteAction extends ExecCommandAction {
@@ -181 +184 @@ class ExecCommandPasteAction extends ExecCommandAction {
- precondition: EditorContextKeys.writable,
+ precondition: (require('vs/platform/contextkey/common/contextkey') as typeof import('vs/platform/contextkey/common/contextkey')).ContextKeyExpr.and(EditorContextKeys.writable, workbench.clipboardContextKey),
@@ -191 +193,2 @@ class ExecCommandPasteAction extends ExecCommandAction {
@@ -191 +194,2 @@ class ExecCommandPasteAction extends ExecCommandAction {
- order: 3
+ order: 3,
+ when: workbench.clipboardContextKey,
@@ -194,0 +198,14 @@ class ExecCommandPasteAction extends ExecCommandAction {
@@ -194,0 +199,26 @@ class ExecCommandPasteAction extends ExecCommandAction {
+
+ public async run(accessor, editor: ICodeEditor): Promise<void> {
+ if (editor instanceof (require('vs/editor/browser/widget/codeEditorWidget') as typeof import('vs/editor/browser/widget/codeEditorWidget')).CodeEditorWidget) {
+ try {
+ editor.trigger('', (require('vs/editor/common/editorCommon') as typeof import ('vs/editor/common/editorCommon')).Handler.Paste, {
+ text: await (require('vs/../../../../packages/vscode/src/workbench') as typeof import ('vs/../../../../packages/vscode/src/workbench')).workbench.clipboardText,
+ editor.focus();
+ const textInput = document.activeElement! as HTMLTextAreaElement;
+ const dataTransfer = new DataTransfer();
+ const value = await clipboard.readText();
+ dataTransfer.setData("text/plain", value);
+ const pasteEvent = new ClipboardEvent("paste", {
+ clipboardData: dataTransfer,
+ });
+ textInput.dispatchEvent(pasteEvent);
+ } catch (ex) {
+ super.run(accessor, editor);
+ try {
+ editor.trigger('', (require('vs/editor/common/editorCommon') as typeof import ('vs/editor/common/editorCommon')).Handler.Paste, {
+ text: await (require('vs/../../../../packages/vscode/src/workbench') as typeof import ('vs/../../../../packages/vscode/src/workbench')).workbench.clipboardText,
+ });
+ } catch (ex) {
+ super.run(accessor, editor);
+ }
+ }
+ } else {
+ super.run(accessor, editor);
Expand Down Expand Up @@ -807,7 +827,7 @@ index 780147c..2e8c9af 100644
- if (platform.isMacintosh) {
+ if (browser.isMacintosh) {
diff --git a/src/vs/workbench/contrib/webview/electron-browser/webview-pre.js b/src/vs/workbench/contrib/webview/electron-browser/webview-pre.js
index 74fc798..03728d0 100644
index 74fc798..0b6b5eb 100644
--- a/src/vs/workbench/contrib/webview/electron-browser/webview-pre.js
+++ b/src/vs/workbench/contrib/webview/electron-browser/webview-pre.js
@@ -10 +10,19 @@
Expand Down Expand Up @@ -846,6 +866,11 @@ index 74fc798..03728d0 100644
+ // supportFetchAPI: true,
+ // corsEnabled: true
+ // });
@@ -328 +346,3 @@
- newFrame.contentWindow.focus();
+ if (document.hasFocus()) {
+ newFrame.contentWindow.focus();
+ }
diff --git a/src/vs/workbench/contrib/webview/electron-browser/webview.contribution.ts b/src/vs/workbench/contrib/webview/electron-browser/webview.contribution.ts
index 484ff86..f3f57cb 100644
--- a/src/vs/workbench/contrib/webview/electron-browser/webview.contribution.ts
Expand Down

0 comments on commit a0cc5d7

Please sign in to comment.