-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from nekowasabi/feat/add-pertical-context
- Loading branch information
Showing
3 changed files
with
42 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ import type { Denops } from "https://deno.land/x/[email protected]/mod.ts"; | |
import * as v from "https://deno.land/x/[email protected]/variable/mod.ts"; | ||
import { ensure, is, maybe } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { aider } from "./aiderCommand.ts"; | ||
import { getPromptFromVimVariable } from "./utils.ts"; | ||
import { getCurrentFilePath, getPromptFromVimVariable } from "./utils.ts"; | ||
|
||
/** | ||
* Enum representing different buffer layout options. | ||
|
@@ -430,3 +430,32 @@ export async function getFileBuffers(denops: Denops): Promise<undefined | string | |
|
||
return buffers.join(" ") ?? undefined; | ||
} | ||
|
||
/** | ||
* 選択したテキストを一時ファイルに保存し、ファイルのパスを返します。 | ||
* | ||
* @param {Denops} denops - Denopsインスタンス | ||
* @param {string} start - 選択範囲の開始行 | ||
* @param {string} end - 選択範囲の終了行 | ||
* @retuns {Promise<string>} 一時ファイルのパス | ||
*/ | ||
export async function getPartialContextFilePath(denops: Denops, start: string, end: string): Promise<string> { | ||
const context = ensure(await denops.call("getline", start, end), is.ArrayOf(is.String)); | ||
const filePath = ensure(await getCurrentFilePath(denops), is.String); | ||
|
||
const annotation = ensure([`// Path: ${filePath}`], is.ArrayOf(is.String)); | ||
|
||
annotation.push(`// Line: ${start}-${end}`); | ||
|
||
context.unshift(...annotation); | ||
|
||
// 一時ファイルに選択範囲を書き込む | ||
const tempFile = ensure(await denops.call("tempname"), is.String); | ||
await Deno.writeTextFile(tempFile, context.join("\n")); | ||
|
||
// set filetype | ||
const fileType = ensure(await fn.getbufvar(denops, "%", "&filetype"), is.String); | ||
await denops.cmd(`setlocal filetype=${fileType}`); | ||
|
||
return tempFile; | ||
} |
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