generated from ellisonleao/nvim-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 5
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 #5 from dlants/lsp-improvements-tests
enhance listBuffers tool
- Loading branch information
Showing
6 changed files
with
166 additions
and
27 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,4 @@ | ||
Moonlight whispers through the trees, | ||
Silver shadows dance with ease. | ||
Stars above like diamonds bright, | ||
Paint their stories in the night. |
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,55 @@ | ||
interface BufferFlags { | ||
hidden: boolean; // 'h' flag | ||
active: boolean; // 'a' flag | ||
current: boolean; // '%' flag | ||
alternate: boolean; // '#' flag | ||
modified: boolean; // '+' flag | ||
readonly: boolean; // '-' flag | ||
terminal: boolean; // 'terminal' flag | ||
} | ||
|
||
interface BufferEntry { | ||
id: number; // Buffer number | ||
flags: BufferFlags; // Parsed status flags | ||
filePath: string; // File path | ||
lineNumber: number; // Current line number | ||
} | ||
|
||
function parseFlags(flagStr: string): BufferFlags { | ||
return { | ||
hidden: flagStr.includes("h"), | ||
active: flagStr.includes("a"), | ||
current: flagStr.includes("%"), | ||
alternate: flagStr.includes("#"), | ||
modified: flagStr.includes("+"), | ||
readonly: flagStr.includes("-"), | ||
terminal: flagStr.includes("t"), | ||
}; | ||
} | ||
|
||
/** | ||
* Parses the output of Neovim's :buffers command into structured data | ||
*lsResponse.output is like: " 1 h \"bun/test/fixtures/poem.txt\" line 1\n 2 a \"bun/test/fixtures/poem2.txt\" line 1" | ||
* see docfiles for :buffers to understand output format | ||
*/ | ||
export function parseLsResponse(response: string): BufferEntry[] { | ||
// Split the response into lines and filter out empty lines | ||
const lines = response.split("\n").filter((line) => line.trim()); | ||
|
||
return lines.map((line) => { | ||
// Remove extra whitespace and split by multiple spaces | ||
const parts = line.trim().split(/\s+/); | ||
|
||
// Extract filepath by finding the quoted string | ||
const filepathStart = line.indexOf('"'); | ||
const filepathEnd = line.lastIndexOf('"'); | ||
const filePath = line.slice(filepathStart + 1, filepathEnd); | ||
|
||
return { | ||
id: parseInt(parts[0], 10), | ||
flags: parseFlags(parts[1]), | ||
filePath, | ||
lineNumber: parseInt(parts[parts.length - 1], 10), | ||
}; | ||
}); | ||
} |