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

Bring to head of internal repo #61

Merged
merged 2 commits into from
Jun 18, 2024
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
4 changes: 2 additions & 2 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# For details, see https://docs.buf.build/configuration/v1/buf-gen-yaml
version: v1
plugins:
- plugin: buf.build/bufbuild/es:v1.4.2
- plugin: buf.build/bufbuild/es:v1.9.0
out: proto
opt:
- target=ts
- import_extension=none
- plugin: buf.build/connectrpc/es:v1.1.3
- plugin: buf.build/connectrpc/es:v1.4.0
out: proto
opt:
- target=ts
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cd -- "$( dirname -- "${BASH_SOURCE[0]}" )"

cd ../../.. && git clean -ffdx -e local.bazelrc && cd -
pnpm install
# If the first arg is public, use npm run build
# If the first arg is public, use pnpm run build
if [[ "$1" == "public" ]]; then
pnpm run build
else
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codeium-chrome",
"version": "1.8.25",
"version": "1.8.58",
"description": "",
"license": "MIT",
"scripts": {
Expand Down Expand Up @@ -28,9 +28,9 @@
"browserslist": "last 10 Chrome versions",
"dependencies": {
"@babel/runtime": "^7.18.6",
"@bufbuild/protobuf": "1.4.2",
"@connectrpc/connect": "1.1.3",
"@connectrpc/connect-web": "1.1.3",
"@bufbuild/protobuf": "1.9.0",
"@connectrpc/connect": "1.4.0",
"@connectrpc/connect-web": "1.4.0",
"@emotion/react": "^11.10.6",
"@emotion/styled": "^11.10.6",
"@mui/icons-material": "^5.11.16",
Expand All @@ -47,7 +47,7 @@
"@babel/preset-env": "^7.21.4",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@bufbuild/buf": "1.28.1",
"@bufbuild/buf": "1.30.1",
"@jupyterlab/application": "^3.5.2",
"@jupyterlab/codeeditor": "^3.5.2",
"@jupyterlab/codemirror": "^3.5.2",
Expand Down
80 changes: 40 additions & 40 deletions pnpm-lock.yaml

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

45 changes: 41 additions & 4 deletions src/codemirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import {

function computeTextAndOffsetsForCodeMirror(
textModels: CodeMirror.Doc[],
currentTextModel: CodeMirror.Doc
currentTextModel: CodeMirror.Doc,
currentTextModelWithOutput: CodeMirror.Doc | undefined
): TextAndOffsets {
return computeTextAndOffsets({
textModels,
currentTextModel,
currentTextModelWithOutput: currentTextModelWithOutput,
utf16CodeUnitOffset: currentTextModel.indexFromPos(currentTextModel.getCursor()),
getText: (model) => model.getValue(),
getLanguage: (model) => language(model, undefined),
Expand Down Expand Up @@ -108,14 +110,16 @@ export class CodeMirrorManager {
async triggerCompletion(
textModels: CodeMirror.Doc[],
currentTextModel: CodeMirror.Doc,
currentTextModelWithOutput: CodeMirror.Doc | undefined,
editorOptions: EditorOptions,
relativePath: string | undefined,
createDisposables: (() => IDisposable[]) | undefined
): Promise<void> {
const cursor = currentTextModel.getCursor();
const { text, utf8ByteOffset, additionalUtf8ByteOffset } = computeTextAndOffsetsForCodeMirror(
textModels,
currentTextModel
currentTextModel,
currentTextModelWithOutput
);
const numUtf8Bytes = additionalUtf8ByteOffset + utf8ByteOffset;
const request = new GetCompletionsRequest({
Expand Down Expand Up @@ -299,7 +303,8 @@ export class CodeMirrorManager {
beforeMainKeyHandler(
doc: CodeMirror.Doc,
event: KeyboardEvent,
alsoHandle: { tab: boolean; escape: boolean }
alsoHandle: { tab: boolean; escape: boolean },
tabKey: string = 'Tab'
): { consumeEvent: boolean | undefined; forceTriggerCompletion: boolean } {
let forceTriggerCompletion = false;
if (event.ctrlKey) {
Expand Down Expand Up @@ -330,13 +335,23 @@ export class CodeMirrorManager {
this.clearCompletion(`key: ${event.key}`);
return { consumeEvent: false, forceTriggerCompletion };
}
// Shift-tab in jupyter notebooks shows documentation.
if (event.key === 'Tab' && event.shiftKey) {
return { consumeEvent: false, forceTriggerCompletion };
}
if (!event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey) {
if (alsoHandle.tab && event.key === 'Tab' && this.acceptCompletion()) {
if (alsoHandle.tab && event.key === tabKey && this.acceptCompletion()) {
return { consumeEvent: true, forceTriggerCompletion };
}
if (alsoHandle.escape && event.key === 'Escape' && this.clearCompletion('user dismissed')) {
return { consumeEvent: true, forceTriggerCompletion };
}
// Special case if we are in jupyter notebooks and the tab key has been rebinded.
// We do not want to consume the default keybinding, because it triggers the default
// jupyter completion.
if (alsoHandle.tab && tabKey != 'Tab') {
return { consumeEvent: false, forceTriggerCompletion };
}
}
const cursor = doc.getCursor();
const characterBeforeCursor =
Expand Down Expand Up @@ -374,6 +389,28 @@ export class CodeMirrorManager {
div.addEventListener('mousedown', () => {
this.clearCompletion('mousedown');
});
const mutationObserver = new MutationObserver(() => {
// Check for jupyterlab-vim command mode.
if (div.classList.contains('cm-fat-cursor')) {
this.clearCompletion('vim');
}
});
mutationObserver.observe(div, {
attributes: true,
attributeFilter: ['class'],
});
const completer = document.body.querySelector('.jp-Completer');
if (completer !== null) {
const completerMutationObserver = new MutationObserver(() => {
if (!completer?.classList.contains('lm-mod-hidden')) {
this.clearCompletion('completer');
}
});
completerMutationObserver.observe(completer, {
attributes: true,
attributeFilter: ['class'],
});
}
};
}
}
Expand Down
1 change: 1 addition & 0 deletions src/codemirrorInject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class CodeMirrorState {
await this.codeMirrorManager.triggerCompletion(
this.docs,
editor.getDoc(),
undefined,
new EditorOptions({
tabSize: BigInt(editor.getOption('tabSize') ?? 4),
insertSpaces: !(editor.getOption('indentWithTabs') ?? false),
Expand Down
4 changes: 3 additions & 1 deletion src/codemirrorLanguages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const MIME_MAP = new Map<string, Language>([
['text/typescript-jsx', Language.TSX],
// mode: mllike
['text/x-ocaml', Language.OCAML],
// Jupyterlab specific
['text/x-ipython', Language.PYTHON],
]);

const MODE_MAP = new Map<string, Language>([
Expand Down Expand Up @@ -95,7 +97,7 @@ export function language(doc: CodeMirror.Doc, path: string | undefined): Languag
}
}
}
const mime = doc.getEditor()?.getOption('mode');
const mime = doc.getEditor()?.getOption('mode') ?? doc.modeOption;
if (typeof mime === 'string') {
const language = MIME_MAP.get(mime);
if (language !== undefined) {
Expand Down
11 changes: 10 additions & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '../proto/exa/language_server_pb/language_server_pb';

const EXTENSION_NAME = 'chrome';
const EXTENSION_VERSION = '1.8.25';
const EXTENSION_VERSION = '1.8.61';

export const CODEIUM_DEBUG = false;

Expand All @@ -22,6 +22,15 @@ export interface ClientSettings {
defaultModel?: string;
}

export interface JupyterLabKeyBindings {
accept: string;
dismiss: string;
}

export interface JupyterNotebookKeyBindings {
accept: string;
}

async function getClientSettings(): Promise<ClientSettings> {
const storageItems = await getStorageItems(['user', 'enterpriseDefaultModel']);
return {
Expand Down
Loading
Loading