Skip to content

set lsp brige port for ask code command #313

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

Open
wants to merge 1 commit 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
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"engines": {
"vscode": "^1.75.0"
},
"extensionDependencies": [
"merico.lang-bridge-vsc"
],
"repository": {
"type": "git",
"url": "https://github.com/devchat-ai/devchat-vscode.git"
Expand Down
4 changes: 3 additions & 1 deletion src/handler/sendMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export async function askCode(message: any, panel: vscode.WebviewPanel|vscode.We
_lastMessage = [message];
_lastMessage[0]['askCode'] = true;

const port = await UiUtilWrapper.getLSPBrigePort();

let pythonVirtualEnv: string|undefined = vscode.workspace.getConfiguration('DevChat').get('PythonVirtualEnv');
if (!pythonVirtualEnv) {
try {
Expand Down Expand Up @@ -91,7 +93,7 @@ export async function askCode(message: any, panel: vscode.WebviewPanel|vscode.We

const commandRun = new CommandRun();
const command = pythonVirtualEnv.trim();
const args = [UiUtilWrapper.extensionPath() + "/tools/askcode_index_query.py", "query", message.text, tempFile];
const args = [UiUtilWrapper.extensionPath() + "/tools/askcode_index_query.py", "query", message.text, tempFile, port];
const result = await commandRun.spawnAsync(command, args, { env: envs, cwd: workspaceDir }, (data) => {
logger.channel()?.info(data);
}, (data) => {
Expand Down
5 changes: 5 additions & 0 deletions src/util/uiUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface UiUtil {
// current selected text
selectText(): string | undefined;
showErrorMessage(message: string): void;
getLSPBrigePort(): Promise<number | undefined>;
}


Expand Down Expand Up @@ -72,5 +73,9 @@ export class UiUtilWrapper {
public static showErrorMessage(message: string): void {
this._uiUtil?.showErrorMessage(message);
}

public static async getLSPBrigePort(): Promise<number | undefined> {
return await this._uiUtil?.getLSPBrigePort();
}
}

5 changes: 5 additions & 0 deletions src/util/uiUtil_vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,9 @@ export class UiUtilVscode implements UiUtil {
public showErrorMessage(message: string): void {
vscode.window.showErrorMessage(message);
}

public async getLSPBrigePort(): Promise<number | undefined> {
const port = await vscode.commands.executeCommand('LangBrige.getAddress') as number | undefined;;
return port;
}
}
10 changes: 6 additions & 4 deletions tools/askcode_index_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def index(repo_path: str):

import json

def query(question: str, doc_context: str):
def query(question: str, doc_context: str, lsp_brige_port: int):
try:
client = get_client(mode=STORAGE_FILE)
q = Q.reuse(
Expand All @@ -135,6 +135,7 @@ def query(question: str, doc_context: str):

ans, docs = chain.run(question)

print(f"LSP brige port: {lsp_brige_port}")
print(f"\n# Question: \n{question}")
print(f"\n# Answer: \n{ans}")
print(f"\n# Relevant Documents: \n")
Expand Down Expand Up @@ -173,13 +174,14 @@ def main():
index(repo_path)

elif command == "query":
if len(sys.argv) < 4:
print("Usage: python index_and_query.py query [question] [doc_context]")
if len(sys.argv) < 5:
print("Usage: python index_and_query.py query [question] [doc_context] [port]")
sys.exit(1)

question = sys.argv[2]
doc_context = sys.argv[3]
query(question, doc_context)
port = sys.argv[4]
query(question, doc_context, port)

else:
print("Invalid command. Available commands: index, query")
Expand Down