VSCode extension: add language field in completion request. (#45)

* vsode ext: add language field in completion request.

* Add comment: language identifier link.

* Add comment: language id link.
add-more-languages
Zhiming Ma 2023-04-05 14:27:23 +08:00 committed by GitHub
parent c86582fcce
commit 0d89a1221a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 11 deletions

View File

@ -16,6 +16,11 @@ if (logAxios) {
}); });
} }
export interface TabbyCompletionRequest {
prompt: string;
language?: string;
}
export interface TabbyCompletion { export interface TabbyCompletion {
id?: string; id?: string;
created?: number; created?: number;
@ -89,14 +94,12 @@ export class TabbyClient extends EventEmitter {
} }
} }
public async getCompletion(prompt: string): Promise<TabbyCompletion | null> { public async getCompletion(request: TabbyCompletionRequest): Promise<TabbyCompletion | null> {
if (this.status == "disconnected") { if (this.status == "disconnected") {
this.ping(); this.ping();
} }
try { try {
const response = await axios.post<TabbyCompletion>(`${this.tabbyServerUrl}/v1/completions`, { const response = await axios.post<TabbyCompletion>(`${this.tabbyServerUrl}/v1/completions`, request);
prompt,
});
assert(response.status == 200); assert(response.status == 200);
return response.data; return response.data;
} catch (e) { } catch (e) {
@ -113,7 +116,7 @@ export class TabbyClient extends EventEmitter {
const response = await axios.post(`${this.tabbyServerUrl}/v1/events`, { const response = await axios.post(`${this.tabbyServerUrl}/v1/events`, {
type: event.type, type: event.type,
completion_id: event.id, completion_id: event.id,
choice_index: event.index choice_index: event.index,
}); });
assert(response.status == 200); assert(response.status == 200);
} catch (e) { } catch (e) {

View File

@ -59,11 +59,15 @@ export class TabbyCompletionProvider implements InlineCompletionItemProvider {
{ {
uuid: this.uuid, uuid: this.uuid,
timestamp: currentTimestamp, timestamp: currentTimestamp,
prompt prompt,
language: document.languageId
} }
); );
// Prompt is already nil-checked // Prompt is already nil-checked
const completion = await this.tabbyClient.getCompletion(prompt as string); const completion = await this.tabbyClient.getCompletion({
prompt: prompt as string,
language: document.languageId, // https://code.visualstudio.com/docs/languages/identifiers
});
const hasSuffixParen = this.hasSuffixParen(document, position); const hasSuffixParen = this.hasSuffixParen(document, position);
const replaceRange = hasSuffixParen const replaceRange = hasSuffixParen

View File

@ -11,7 +11,7 @@ const webpack = require("webpack");
/** @type WebpackConfig */ /** @type WebpackConfig */
const extensionNodeConfig = { const extensionNodeConfig = {
target: 'node', // VS Code extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/ target: 'node', // VS Code extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production') mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production')
entry: './src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/ entry: './src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
output: { output: {
@ -49,7 +49,7 @@ const extensionNodeConfig = {
const extensionWebConfig = { const extensionWebConfig = {
target: 'webworker', // VS Code extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/ target: 'webworker', // VS Code extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production') mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production')
entry: './src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/ entry: './src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
output: { output: {
@ -103,4 +103,4 @@ const extensionWebConfig = {
}, },
}; };
module.exports = [ extensionNodeConfig, extensionWebConfig ]; module.exports = [extensionNodeConfig, extensionWebConfig];

View File

@ -8,7 +8,7 @@ class Choice(BaseModel):
index: int index: int
text: str text: str
# https://code.visualstudio.com/docs/languages/identifiers
class Language(str, Enum): class Language(str, Enum):
UNKNOWN = "unknown" UNKNOWN = "unknown"
PYTHON = "python" PYTHON = "python"