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 #65

Merged
merged 1 commit into from
Aug 21, 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
8 changes: 3 additions & 5 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# buf.gen.yaml defines a local generation template.
# For details, see https://docs.buf.build/configuration/v1/buf-gen-yaml
version: v1
version: v2
plugins:
- plugin: buf.build/bufbuild/es:v1.9.0
- local: node_modules/@bufbuild/protoc-gen-es/bin/protoc-gen-es
out: proto
opt:
- target=ts
- import_extension=none
- plugin: buf.build/connectrpc/es:v1.4.0
- local: node_modules/@connectrpc/protoc-gen-connect-es/bin/protoc-gen-connect-es
out: proto
opt:
- target=ts
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codeium-chrome",
"version": "1.8.70",
"version": "1.12.7",
"description": "",
"license": "MIT",
"scripts": {
Expand Down Expand Up @@ -47,7 +47,9 @@
"@babel/preset-env": "^7.21.4",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@bufbuild/buf": "1.30.1",
"@bufbuild/buf": "1.36.0",
"@bufbuild/protoc-gen-es": "1.9.0",
"@connectrpc/protoc-gen-connect-es": "1.4.0",
"@jupyterlab/application": "^3.5.2",
"@jupyterlab/codeeditor": "^3.5.2",
"@jupyterlab/codemirror": "^3.5.2",
Expand Down
130 changes: 106 additions & 24 deletions pnpm-lock.yaml

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

4 changes: 4 additions & 0 deletions src/codemirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '../proto/exa/language_server_pb/language_server_pb';

function computeTextAndOffsetsForCodeMirror(
isNotebook: boolean,
textModels: CodeMirror.Doc[],
currentTextModel: CodeMirror.Doc,
currentTextModelWithOutput: CodeMirror.Doc | undefined
Expand All @@ -21,6 +22,7 @@ function computeTextAndOffsetsForCodeMirror(
textModels,
currentTextModel,
currentTextModelWithOutput: currentTextModelWithOutput,
isNotebook: isNotebook,
utf16CodeUnitOffset: currentTextModel.indexFromPos(currentTextModel.getCursor()),
getText: (model) => model.getValue(),
getLanguage: (model) => language(model, undefined),
Expand Down Expand Up @@ -108,6 +110,7 @@ export class CodeMirrorManager {
}

async triggerCompletion(
isNotebook: boolean,
textModels: CodeMirror.Doc[],
currentTextModel: CodeMirror.Doc,
currentTextModelWithOutput: CodeMirror.Doc | undefined,
Expand All @@ -117,6 +120,7 @@ export class CodeMirrorManager {
): Promise<void> {
const cursor = currentTextModel.getCursor();
const { text, utf8ByteOffset, additionalUtf8ByteOffset } = computeTextAndOffsetsForCodeMirror(
isNotebook,
textModels,
currentTextModel,
currentTextModelWithOutput
Expand Down
1 change: 1 addition & 0 deletions src/codemirrorInject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class CodeMirrorState {
}

await this.codeMirrorManager.triggerCompletion(
false, // isNotebook
this.docs,
editor.getDoc(),
undefined,
Expand Down
2 changes: 1 addition & 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.70';
const EXTENSION_VERSION = '1.12.7';

export const CODEIUM_DEBUG = false;

Expand Down
1 change: 1 addition & 0 deletions src/jupyterInject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class JupyterState {
const relativePath = path.endsWith('.ipynb') ? path : undefined;

await codeMirrorManager.triggerCompletion(
true, // isNotebook
textModels,
this.code_mirror.getDoc(),
currentModelWithOutput,
Expand Down
1 change: 1 addition & 0 deletions src/jupyterlabPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class CodeiumPlugin {
const context = widget !== null ? this.documentManager.contextForWidget(widget) : undefined;
const currentTextModel = codeMirrorEditor.doc;
await this.codeMirrorManager.triggerCompletion(
true, // isNotebook
textModels,
currentTextModel,
currentTextModelWithOutput,
Expand Down
11 changes: 11 additions & 0 deletions src/monacoCompletionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,14 @@ export class MonacoCompletionProvider implements monaco.languages.InlineCompleti
// Perhaps add something for (Stackblitz or Quadratic)?
}

private isNotebook() {
return (
OMonacoSite.COLAB === this.monacoSite ||
OMonacoSite.DATABRICKS === this.monacoSite ||
OMonacoSite.DEEPNOTE === this.monacoSite
);
}

private absolutePath(model: monaco.editor.ITextModel): string | undefined {
// Given we are using path, note the docs on fsPath: https://microsoft.github.io/monaco-editor/api/classes/monaco.Uri.html#fsPath
return model.uri.path;
Expand Down Expand Up @@ -328,6 +336,7 @@ export class MonacoCompletionProvider implements monaco.languages.InlineCompleti
const valueAndStartOffset = getValueAndStartOffset(this.monacoSite, model);
// computeTextAndOffsets is receiving shortened strings.
return computeTextAndOffsets({
isNotebook: this.isNotebook(),
textModels: rawTexts.map((m) => getValueAndStartOffset(this.monacoSite, m).value),
currentTextModel: valueAndStartOffset.value,
utf16CodeUnitOffset: model.getOffsetAt(position) - valueAndStartOffset.utf16Offset,
Expand Down Expand Up @@ -384,6 +393,7 @@ export class MonacoCompletionProvider implements monaco.languages.InlineCompleti
}
const valueAndStartOffset = getValueAndStartOffset(this.monacoSite, model);
return computeTextAndOffsets({
isNotebook: this.isNotebook(),
textModels: rawTexts.map((m) => getValueAndStartOffset(this.monacoSite, m).value),
currentTextModel: valueAndStartOffset.value,
utf16CodeUnitOffset: model.getOffsetAt(position) - valueAndStartOffset.utf16Offset,
Expand All @@ -397,6 +407,7 @@ export class MonacoCompletionProvider implements monaco.languages.InlineCompleti
});
}
return computeTextAndOffsets({
isNotebook: this.isNotebook(),
textModels: this.textModels(model),
currentTextModel: model,
utf16CodeUnitOffset:
Expand Down
10 changes: 6 additions & 4 deletions src/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export interface MaybeNotebook<T> {
readonly textModels: T[];
readonly currentTextModel: T;
readonly currentTextModelWithOutput?: T;
// Whether the document is a notebook. For notebooks, we will prepend with \nCELL:\n
readonly isNotebook: boolean;
// The offset into the value of getText(currentTextModel) at which to trigger a completion.
readonly utf16CodeUnitOffset: number;
getText(model: T): string;
Expand All @@ -54,7 +56,8 @@ export function computeTextAndOffsets<T>(maybeNotebook: MaybeNotebook<T>): TextA
relevantDocumentTexts
.map((el) => numCodeUnitsToNumUtf8Bytes(el))
.reduce((a, b) => a + b, 0) +
cellSplitString.length * (relevantDocumentTexts.length + 1);
cellSplitString.length *
(relevantDocumentTexts.length + (maybeNotebook.isNotebook ? 1 : 0));
found = true;
}
const previousModelLanguage = maybeNotebook.getLanguage(previousModel, idx);
Expand Down Expand Up @@ -87,9 +90,8 @@ export function computeTextAndOffsets<T>(maybeNotebook: MaybeNotebook<T>): TextA
const currentModelText = maybeNotebook.getText(
maybeNotebook.currentTextModelWithOutput ?? maybeNotebook.currentTextModel
);
const text = found
? `${cellSplitString}${relevantDocumentTexts.join(cellSplitString)}`
: `${cellSplitString}${currentModelText}`;
let text = found ? `${relevantDocumentTexts.join(cellSplitString)}` : `${currentModelText}`;
text = maybeNotebook.isNotebook ? `${cellSplitString}${text}` : text;
const utf8ByteOffset = numCodeUnitsToNumUtf8Bytes(
currentModelText,
maybeNotebook.utf16CodeUnitOffset
Expand Down
2 changes: 1 addition & 1 deletion static/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Codeium: AI Code Autocompletion on all IDEs",
"description": "Your modern coding superpower. Get code completions in Colab and more.",
"version": "1.8.70",
"version": "1.12.7",
"manifest_version": 3,
"background": {
"service_worker": "serviceWorker.js"
Expand Down
Loading