-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(vscode): chat panel use file as context when no selection.
- Loading branch information
Showing
7 changed files
with
64 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { TextEditor } from "vscode"; | ||
import dedent from "dedent"; | ||
import type { EditorContext } from "tabby-chat-panel"; | ||
import type { GitProvider } from "../git/GitProvider"; | ||
import { localUriToChatPanelFilepath, vscodeRangeToChatPanelPositionRange } from "./utils"; | ||
|
||
// default: use selection if available, otherwise use the whole file | ||
// selection: use selection if available, otherwise return null | ||
// file: use the whole file | ||
export type RangeStrategy = "default" | "selection" | "file"; | ||
|
||
export async function getEditorContext( | ||
editor: TextEditor, | ||
gitProvider: GitProvider, | ||
rangeStrategy: RangeStrategy = "default", | ||
): Promise<EditorContext | null> { | ||
let range = rangeStrategy !== "file" ? editor.selection : undefined; | ||
let text = !range?.isEmpty ? editor.document.getText(range) : ""; | ||
if (!text || text.trim().length < 1) { | ||
if (rangeStrategy === "selection") { | ||
return null; | ||
} else if (range !== undefined) { | ||
range = undefined; | ||
text = editor.document.getText(); | ||
} | ||
} | ||
const content = range !== undefined ? dedent(text) : text; | ||
|
||
return { | ||
kind: "file", | ||
filepath: localUriToChatPanelFilepath(editor.document.uri, gitProvider), | ||
range: range ? vscodeRangeToChatPanelPositionRange(range) : undefined, | ||
content, | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.