mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-21 12:51:17 -05:00
Make mentions clickable
This commit is contained in:
@@ -28,6 +28,7 @@ class WorkspaceTracker {
|
||||
|
||||
private registerListeners() {
|
||||
// Listen for file creation
|
||||
// .bind(this) ensures the callback refers to class instance when using this, not necessary when using arrow function
|
||||
this.disposables.push(vscode.workspace.onDidCreateFiles(this.onFilesCreated.bind(this)))
|
||||
|
||||
// Listen for file deletion
|
||||
|
||||
@@ -12,6 +12,7 @@ import axios from "axios"
|
||||
import { getTheme } from "../utils/getTheme"
|
||||
import { openFile, openImage } from "../utils/open-file"
|
||||
import WorkspaceTracker from "../integrations/WorkspaceTracker"
|
||||
import { openMention } from "../utils/context-mentions"
|
||||
|
||||
/*
|
||||
https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts
|
||||
@@ -423,6 +424,9 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
|
||||
case "openFile":
|
||||
openFile(message.text!)
|
||||
break
|
||||
case "openMention":
|
||||
openMention(message.text)
|
||||
break
|
||||
// Add more switch case statements here as more webview message commands
|
||||
// are created within the webview context (i.e. inside media/main.js)
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ export interface WebviewMessage {
|
||||
| "requestOllamaModels"
|
||||
| "openImage"
|
||||
| "openFile"
|
||||
| "openMention"
|
||||
text?: string
|
||||
askResponse?: ClaudeAskResponse
|
||||
apiConfiguration?: ApiConfiguration
|
||||
|
||||
9
src/shared/context-mentions.ts
Normal file
9
src/shared/context-mentions.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
Mention regex
|
||||
- File and folder paths (starting with '/')
|
||||
- URLs (containing '://')
|
||||
- The 'problems' keyword
|
||||
- Word boundary after 'problems' to avoid partial matches
|
||||
*/
|
||||
export const mentionRegex = /@((?:\/|\w+:\/\/)[^\s]+|problems\b)/
|
||||
export const mentionRegexGlobal = new RegExp(mentionRegex.source, "g")
|
||||
28
src/utils/context-mentions.ts
Normal file
28
src/utils/context-mentions.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import * as vscode from "vscode"
|
||||
import * as path from "path"
|
||||
import { openFile } from "./open-file"
|
||||
|
||||
export function openMention(mention?: string): void {
|
||||
if (!mention) {
|
||||
return
|
||||
}
|
||||
|
||||
if (mention.startsWith("/")) {
|
||||
const relPath = mention.slice(1)
|
||||
const cwd = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0)
|
||||
if (!cwd) {
|
||||
return
|
||||
}
|
||||
const absPath = path.resolve(cwd, relPath)
|
||||
if (mention.endsWith("/")) {
|
||||
vscode.commands.executeCommand("revealInExplorer", vscode.Uri.file(absPath))
|
||||
// vscode.commands.executeCommand("vscode.openFolder", , { forceNewWindow: false }) opens in new window
|
||||
} else {
|
||||
openFile(absPath)
|
||||
}
|
||||
} else if (mention === "problems") {
|
||||
vscode.commands.executeCommand("workbench.actions.view.problems")
|
||||
} else if (mention.startsWith("http")) {
|
||||
vscode.env.openExternal(vscode.Uri.parse(mention))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user