diff --git a/slug/apps/kang/backend.js b/slug/apps/kang/backend.js index a62c3888..478c5831 100755 --- a/slug/apps/kang/backend.js +++ b/slug/apps/kang/backend.js @@ -95,6 +95,7 @@ if (parsedArgs.values['test-highlight']) { absolutePath, relativePath, newFile, + hasLanguageModel: !!doHighlight, }); // TODO thread stdin in case it had some data in it before we went to web mode // send a secret message and wait for it to come back. @@ -116,16 +117,16 @@ function setupHighlight() { terminal: false, }); rl.on('line', line => { - const {id, tokens, error} = JSON.parse(line); + const {id, result, error} = JSON.parse(line); if (error) higlightCallbacks.get(id).reject(new Error(error)); else - higlightCallbacks.get(id).resolve(tokens); + higlightCallbacks.get(id).resolve(result); }); process.on('beforeExit', () => { commandChild.kill(); }); return (content, id) => { - commandChild.stdin.write(JSON.stringify({content, id}) + '\n'); + commandChild.stdin.write(JSON.stringify({method: 'highlight', params: {content}, id}) + '\n'); }; } \ No newline at end of file diff --git a/slug/apps/kang/web.ts b/slug/apps/kang/web.ts index 56ebe2c3..19058a66 100644 --- a/slug/apps/kang/web.ts +++ b/slug/apps/kang/web.ts @@ -133,7 +133,7 @@ const rpc = RPC(transport, { } }); window['editorForTest'] = editor; - updateEditorMode(true); + updateEditorMode(!params.hasLanguageModel); editorContainer.append(editor.element); editor.layout(); lastSavedVersion = editor.value; diff --git a/slug/editor/js/highlighter.ts b/slug/editor/js/highlighter.ts index d659e91f..399d6282 100644 --- a/slug/editor/js/highlighter.ts +++ b/slug/editor/js/highlighter.ts @@ -21,7 +21,7 @@ export class Highlighter extends Emitter<{ 'highlight': {from: number, to: number}; }> { private _selectionColors: {color?: string, background?: string}; - private _mode: Mode; + private _mode: Mode | null; private _lineInfo = new WeakMap}>(); private _currentLineNumber = 0; private _requestLineNumber = 0; @@ -176,6 +176,8 @@ export class Highlighter extends Emitter<{ } indentation(lineNumber: number): number { + if (!this._mode) + return 0; const line = this._model.line(lineNumber); if (!this._lineInfo.has(line)) return 0; @@ -265,7 +267,7 @@ export class Highlighter extends Emitter<{ } hoverForLocation(loc: Loc): { content: string | Node, reposition: Loc } | null { - if (!this._mode.hover) + if (!this._mode?.hover) return null; const line = this._model.line(loc.line); if (!line) diff --git a/slug/sdk/index.js b/slug/sdk/index.js index 1f9b2951..5ec3744e 100644 --- a/slug/sdk/index.js +++ b/slug/sdk/index.js @@ -44,8 +44,14 @@ class Transport { this._sawSecret = true; } setImmediate(() => { - if (this.onmessage) - this.onmessage.call(null, JSON.parse(message)); + let parsed; + try { + parsed = JSON.parse(message); + } catch { + console.error(JSON.stringify(message)); + throw new Error('failed to parse json'); + } + this.onmessage.call(null, parsed); }); }; sendMessage(this._pendingMessage + buffer.toString(undefined, 0, end));