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

Refactored code to make use of interface generics from monaco-editor #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"packageManager": "[email protected]",
"scripts": {
"generate": "rm -rf ./src/proto && node generate.js",
"generate": "rm -rf ./src/api/proto && node generate.js",
"rollup": "rollup -c",
"clean": "rm -rf node_modules && rm -rf dist",
"test": "echo \"Error: no test specified\" && exit 1",
Expand Down
34 changes: 7 additions & 27 deletions src/components/CodeiumEditor/CompletionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,7 @@ import {
} from "../../api/proto/exa/codeium_common_pb/codeium_common_pb";
import { Status } from "./Status";
import { uuid } from "../../utils/uuid";

class MonacoInlineCompletion implements monaco.languages.InlineCompletion {
readonly insertText: string;
// TODO(prem): Why is this property needed?
readonly text: string;
readonly range: monaco.IRange;
readonly command: {
id: string;
title: string;
arguments: string[];
};

constructor(insertText: string, range: monaco.IRange, completionId: string) {
this.insertText = insertText;
this.text = insertText;
this.range = range;
this.command = {
id: "codeium.acceptCompletion",
title: "Accept Completion",
arguments: [completionId, insertText],
};
}
}
import MonacoInlineCompletion from "./InlineCompletion";

/**
* CompletionProvider class for Codeium.
Expand Down Expand Up @@ -81,8 +59,7 @@ export class MonacoCompletionProvider {
monacoPosition: monaco.Position,
token: CancellationToken
): Promise<
| monaco.languages.InlineCompletions<monaco.languages.InlineCompletion>
| undefined
monaco.languages.InlineCompletions<MonacoInlineCompletion> | undefined
> {
const document = new Document(model);
const position = Position.fromMonaco(monacoPosition);
Expand Down Expand Up @@ -144,7 +121,10 @@ export class MonacoCompletionProvider {
.map((completionItem) =>
this.createInlineCompletionItem(completionItem, document)
)
.filter((item) => !!item);
.filter(
(item?: MonacoInlineCompletion): item is MonacoInlineCompletion =>
!!item
);

this.setStatus(Status.SUCCESS);
let message = `Generated ${inlineCompletionItems.length} completions`;
Expand All @@ -154,7 +134,7 @@ export class MonacoCompletionProvider {
this.setMessage(message);

return {
items: inlineCompletionItems as monaco.languages.InlineCompletion[],
items: inlineCompletionItems,
};
}

Expand Down
26 changes: 26 additions & 0 deletions src/components/CodeiumEditor/InlineCompletion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as monaco from "monaco-editor/esm/vs/editor/editor.api";

export default class MonacoInlineCompletion
implements monaco.languages.InlineCompletion
{
readonly insertText: string;
// TODO(prem): Why is this property needed?
readonly text: string;
readonly range: monaco.IRange;
readonly command: {
id: string;
title: string;
arguments: string[];
};

constructor(insertText: string, range: monaco.IRange, completionId: string) {
this.insertText = insertText;
this.text = insertText;
this.range = range;
this.command = {
id: "codeium.acceptCompletion",
title: "Accept Completion",
arguments: [completionId, insertText],
};
}
}
6 changes: 5 additions & 1 deletion src/components/CodeiumEditor/InlineCompletionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PromiseClient } from "@connectrpc/connect";
import { Status } from "./Status";
import { MonacoCompletionProvider } from "./CompletionProvider";
import { LanguageServerService } from "../../api/proto/exa/language_server_pb/language_server_connect";
import MonacoInlineCompletion from "./InlineCompletion";

declare module "monaco-editor" {
namespace editor {
Expand All @@ -14,7 +15,10 @@ declare module "monaco-editor" {
}

export class InlineCompletionProvider
implements monaco.languages.InlineCompletionsProvider
implements
monaco.languages.InlineCompletionsProvider<
monaco.languages.InlineCompletions<MonacoInlineCompletion>
>
{
private numCompletionsProvided: number;
readonly completionProvider: MonacoCompletionProvider;
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"declarationDir": "types",
"sourceMap": true,
"outDir": "dist",
"moduleResolution": "node",
"moduleResolution": "Bundler",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for changing the module resolution to Bundler?

"allowSyntheticDefaultImports": true,
"emitDeclarationOnly": true
}
Expand Down