feat(core): file context improvements and option to disable (#24661)
This commit is contained in:
parent
51fc10e407
commit
fab1768826
3 changed files with 33 additions and 15 deletions
|
|
@ -727,6 +727,15 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
|
||||||
dialog.clear()
|
dialog.clear()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: kv.get("file_context_enabled", true) ? "Disable file context" : "Enable file context",
|
||||||
|
value: "app.toggle.file_context",
|
||||||
|
category: "System",
|
||||||
|
onSelect: (dialog) => {
|
||||||
|
kv.set("file_context_enabled", !kv.get("file_context_enabled", true))
|
||||||
|
dialog.clear()
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: kv.get("diff_wrap_mode", "word") === "word" ? "Disable diff wrapping" : "Enable diff wrapping",
|
title: kv.get("diff_wrap_mode", "word") === "word" ? "Disable diff wrapping" : "Enable diff wrapping",
|
||||||
value: "app.toggle.diffwrap",
|
value: "app.toggle.diffwrap",
|
||||||
|
|
|
||||||
|
|
@ -112,9 +112,10 @@ export function Prompt(props: PromptProps) {
|
||||||
const animationsEnabled = createMemo(() => kv.get("animations_enabled", true))
|
const animationsEnabled = createMemo(() => kv.get("animations_enabled", true))
|
||||||
const list = createMemo(() => props.placeholders?.normal ?? [])
|
const list = createMemo(() => props.placeholders?.normal ?? [])
|
||||||
const shell = createMemo(() => props.placeholders?.shell ?? [])
|
const shell = createMemo(() => props.placeholders?.shell ?? [])
|
||||||
const editorPath = createMemo(() => editor.selection()?.filePath)
|
const fileContextEnabled = createMemo(() => kv.get("file_context_enabled", true))
|
||||||
|
const editorPath = createMemo(() => (fileContextEnabled() ? editor.selection()?.filePath : undefined))
|
||||||
const editorSelectionLabel = createMemo(() => {
|
const editorSelectionLabel = createMemo(() => {
|
||||||
const selection = editor.selection()?.selection
|
const selection = fileContextEnabled() ? editor.selection()?.selection : undefined
|
||||||
if (!selection) return
|
if (!selection) return
|
||||||
if (selection.start.line === selection.end.line && selection.start.character === selection.end.character) return
|
if (selection.start.line === selection.end.line && selection.start.character === selection.end.character) return
|
||||||
if (selection.start.line === selection.end.line) return `#${selection.start.line}`
|
if (selection.start.line === selection.end.line) return `#${selection.start.line}`
|
||||||
|
|
@ -746,7 +747,7 @@ export function Prompt(props: PromptProps) {
|
||||||
// Capture mode before it gets reset
|
// Capture mode before it gets reset
|
||||||
const currentMode = store.mode
|
const currentMode = store.mode
|
||||||
const variant = local.model.variant.current()
|
const variant = local.model.variant.current()
|
||||||
const editorSelection = editor.selection()
|
const editorSelection = fileContextEnabled() ? editor.selection() : undefined
|
||||||
const editorParts = editorSelection
|
const editorParts = editorSelection
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
|
|
@ -755,13 +756,17 @@ export function Prompt(props: PromptProps) {
|
||||||
text: (() => {
|
text: (() => {
|
||||||
const start = editorSelection.selection.start
|
const start = editorSelection.selection.start
|
||||||
const end = editorSelection.selection.end
|
const end = editorSelection.selection.end
|
||||||
|
|
||||||
|
let text = ""
|
||||||
if (start.line === end.line && start.character === end.character) {
|
if (start.line === end.line && start.character === end.character) {
|
||||||
return `Note: The user opened the file "${editorSelection.filePath}".`
|
text = `Note: The user opened the file "${editorSelection.filePath}".`
|
||||||
|
} else if (start.line === end.line) {
|
||||||
|
text = `Note: The user selected line ${start.line + 1} from "${editorSelection.filePath}". \`\`\`${editorSelection.text}\`\`\`\n\n`
|
||||||
|
} else {
|
||||||
|
text = `Note: The user selected lines ${start.line + 1} to ${end.line + 1} from "${editorSelection.filePath}". \`\`\`${editorSelection.text}\`\`\`\n\n`
|
||||||
}
|
}
|
||||||
if (start.line === end.line) {
|
|
||||||
return `Note: The user selected line ${start.line} from "${editorSelection.filePath}": ${editorSelection.text}`
|
return `<system-reminder>${text} This may or may not be relevant to the current task.</system-reminder>\n`
|
||||||
}
|
|
||||||
return `Note: The user selected lines ${start.line} to ${end.line} from "${editorSelection.filePath}": ${editorSelection.text}`
|
|
||||||
})(),
|
})(),
|
||||||
synthetic: true,
|
synthetic: true,
|
||||||
metadata: {
|
metadata: {
|
||||||
|
|
@ -835,6 +840,7 @@ export function Prompt(props: PromptProps) {
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
.catch(() => {})
|
.catch(() => {})
|
||||||
|
editor.clearSelection()
|
||||||
}
|
}
|
||||||
history.append({
|
history.append({
|
||||||
...store.prompt,
|
...store.prompt,
|
||||||
|
|
|
||||||
|
|
@ -108,9 +108,11 @@ export const { use: useEditorContext, provider: EditorContextProvider } = create
|
||||||
send({ id: requestID, method, params })
|
send({ id: requestID, method, params })
|
||||||
}
|
}
|
||||||
|
|
||||||
const scheduleReconnect = (delay: number) => {
|
const scheduleReconnect = () => {
|
||||||
if (closed) return
|
if (closed) return
|
||||||
if (reconnect) clearTimeout(reconnect)
|
if (reconnect) clearTimeout(reconnect)
|
||||||
|
attempt += 1
|
||||||
|
const delay = Math.min(1000 * 2 ** (attempt - 1), 10_000)
|
||||||
reconnect = setTimeout(connect, delay)
|
reconnect = setTimeout(connect, delay)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,7 +124,7 @@ export const { use: useEditorContext, provider: EditorContextProvider } = create
|
||||||
const dbPath = resolveZedDbPath()
|
const dbPath = resolveZedDbPath()
|
||||||
if (!dbPath) {
|
if (!dbPath) {
|
||||||
setStore("status", "disabled")
|
setStore("status", "disabled")
|
||||||
scheduleReconnect(1000)
|
scheduleReconnect()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
zedSelection ??= resolveZedSelection(dbPath)
|
zedSelection ??= resolveZedSelection(dbPath)
|
||||||
|
|
@ -143,7 +145,7 @@ export const { use: useEditorContext, provider: EditorContextProvider } = create
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
zedSelection = undefined
|
zedSelection = undefined
|
||||||
})
|
})
|
||||||
scheduleReconnect(1000)
|
scheduleReconnect()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -207,13 +209,11 @@ export const { use: useEditorContext, provider: EditorContextProvider } = create
|
||||||
if (closed) return
|
if (closed) return
|
||||||
|
|
||||||
setStore("status", "connecting")
|
setStore("status", "connecting")
|
||||||
attempt += 1
|
scheduleReconnect()
|
||||||
const delay = Math.min(1000 * 2 ** (attempt - 1), 30000)
|
|
||||||
scheduleReconnect(delay)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
scheduleReconnect(0)
|
connect()
|
||||||
|
|
||||||
onCleanup(() => {
|
onCleanup(() => {
|
||||||
closed = true
|
closed = true
|
||||||
|
|
@ -232,6 +232,9 @@ export const { use: useEditorContext, provider: EditorContextProvider } = create
|
||||||
selection() {
|
selection() {
|
||||||
return store.selection
|
return store.selection
|
||||||
},
|
},
|
||||||
|
clearSelection() {
|
||||||
|
setStore("selection", undefined)
|
||||||
|
},
|
||||||
onMention(listener: (mention: EditorMention) => void) {
|
onMention(listener: (mention: EditorMention) => void) {
|
||||||
mentionListeners.add(listener)
|
mentionListeners.add(listener)
|
||||||
return () => mentionListeners.delete(listener)
|
return () => mentionListeners.delete(listener)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue