- Add `textEdits.ts` for applying LSP text edits and collecting workspace edits. - Introduce `AgentSymbol` interface in `types/index.ts` for agent-facing symbol descriptors. - Create tests for `buildSubAgentExecutionSteps` to validate execution states and tool handling. - Add tests for `parseSymbolToolResult` to ensure correct extraction of symbol paths and locations. - Enhance document read tools tests to cover new LSP functionalities and symbol searching. - Implement loop detection tests for semantic navigation and document reading. - Establish integration tests for LSP bundled servers to verify symbol retrieval. - Create tests for document ownership management in the main process. - Add LSP protocol helper tests to validate JSON-RPC interactions. - Implement server routing tests for LSP project configurations. - Add tests for agent symbols to ensure correct symbol pathing and extraction. - Validate language support contract for LSP routing and extensions. - Create tests for LSP text edits to ensure correct application and error handling.
31 lines
1.5 KiB
TypeScript
31 lines
1.5 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { applyLspTextEdits, collectWorkspaceTextEdits } from '../../src/shared/lsp/textEdits'
|
|
|
|
describe('LSP text edits', () => {
|
|
it('applies multiple edits against the original document coordinates', () => {
|
|
expect(applyLspTextEdits('const one = 1;\r\nconst two = 2;\r\n', [
|
|
{ range: { start: { line: 1, character: 6 }, end: { line: 1, character: 9 } }, newText: 'second' },
|
|
{ range: { start: { line: 0, character: 6 }, end: { line: 0, character: 9 } }, newText: 'first' },
|
|
])).toBe('const first = 1;\r\nconst second = 2;\r\n')
|
|
})
|
|
|
|
it('rejects stale, invalid, and overlapping ranges', () => {
|
|
expect(() => applyLspTextEdits('abc', [
|
|
{ range: { start: { line: 0, character: 1 }, end: { line: 0, character: 3 } }, newText: '' },
|
|
{ range: { start: { line: 0, character: 2 }, end: { line: 0, character: 3 } }, newText: '' },
|
|
])).toThrow(/Overlapping/)
|
|
expect(() => applyLspTextEdits('abc', [
|
|
{ range: { start: { line: 2, character: 0 }, end: { line: 2, character: 0 } }, newText: '' },
|
|
])).toThrow(/outside/)
|
|
})
|
|
|
|
it('merges changes and text document edits by URI', () => {
|
|
const edit = { range: { start: { line: 0, character: 0 }, end: { line: 0, character: 0 } }, newText: 'x' }
|
|
const collected = collectWorkspaceTextEdits({
|
|
changes: { 'file:///a.ts': [edit] },
|
|
documentChanges: [{ textDocument: { uri: 'file:///a.ts' }, edits: [edit] }],
|
|
})
|
|
expect(collected.get('file:///a.ts')).toHaveLength(2)
|
|
})
|
|
})
|