diff --git a/integrationtests/fixtures/snapshots/go/codelens/get.snap b/integrationtests/fixtures/snapshots/go/codelens/get.snap index e337ba9..b82dbfb 100644 --- a/integrationtests/fixtures/snapshots/go/codelens/get.snap +++ b/integrationtests/fixtures/snapshots/go/codelens/get.snap @@ -1,5 +1,4 @@ /TEST_OUTPUT/workspace/go.mod: -=== [1] Location: Lines 1-1 Title: Reset go.mod diagnostics diff --git a/integrationtests/fixtures/snapshots/go/definition/constant.snap b/integrationtests/fixtures/snapshots/go/definition/constant.snap index e920542..35482d8 100644 --- a/integrationtests/fixtures/snapshots/go/definition/constant.snap +++ b/integrationtests/fixtures/snapshots/go/definition/constant.snap @@ -1,10 +1,10 @@ -=== +--- + Symbol: TestConstant /TEST_OUTPUT/workspace/clean.go Kind: Constant Container Name: github.com/isaacphi/mcp-language-server/integrationtests/test-output/go/workspace -Start Position: Line 25, Column 1 -End Position: Line 25, Column 38 -=== +Range: L25:C1 - L25:C38 + 25|const TestConstant = "constant value" diff --git a/integrationtests/fixtures/snapshots/go/definition/foobar.snap b/integrationtests/fixtures/snapshots/go/definition/foobar.snap index 3d8fec2..d75e774 100644 --- a/integrationtests/fixtures/snapshots/go/definition/foobar.snap +++ b/integrationtests/fixtures/snapshots/go/definition/foobar.snap @@ -1,13 +1,14 @@ -=== +--- + Symbol: FooBar /TEST_OUTPUT/workspace/main.go Kind: Function Container Name: github.com/isaacphi/mcp-language-server/integrationtests/test-output/go/workspace -Start Position: Line 6, Column 1 -End Position: Line 9, Column 2 -=== +Range: L6:C1 - L10:C2 + 6|func FooBar() string { 7| return "Hello, World!" 8| fmt.Println("Unreachable code") // This is unreachable code - 9|} + 9| return 3 +10|} diff --git a/integrationtests/fixtures/snapshots/go/definition/function.snap b/integrationtests/fixtures/snapshots/go/definition/function.snap index 16e0d1d..e9b6b4a 100644 --- a/integrationtests/fixtures/snapshots/go/definition/function.snap +++ b/integrationtests/fixtures/snapshots/go/definition/function.snap @@ -1,11 +1,11 @@ -=== +--- + Symbol: TestFunction /TEST_OUTPUT/workspace/clean.go Kind: Function Container Name: github.com/isaacphi/mcp-language-server/integrationtests/test-output/go/workspace -Start Position: Line 31, Column 1 -End Position: Line 33, Column 2 -=== +Range: L31:C1 - L33:C2 + 31|func TestFunction() { 32| fmt.Println("This is a test function") 33|} diff --git a/integrationtests/fixtures/snapshots/go/definition/interface.snap b/integrationtests/fixtures/snapshots/go/definition/interface.snap index ba97017..aaddc55 100644 --- a/integrationtests/fixtures/snapshots/go/definition/interface.snap +++ b/integrationtests/fixtures/snapshots/go/definition/interface.snap @@ -1,11 +1,11 @@ -=== +--- + Symbol: TestInterface /TEST_OUTPUT/workspace/clean.go Kind: Interface Container Name: github.com/isaacphi/mcp-language-server/integrationtests/test-output/go/workspace -Start Position: Line 17, Column 1 -End Position: Line 19, Column 2 -=== +Range: L17:C1 - L19:C2 + 17|type TestInterface interface { 18| DoSomething() error 19|} diff --git a/integrationtests/fixtures/snapshots/go/definition/method.snap b/integrationtests/fixtures/snapshots/go/definition/method.snap index 6704576..7084bef 100644 --- a/integrationtests/fixtures/snapshots/go/definition/method.snap +++ b/integrationtests/fixtures/snapshots/go/definition/method.snap @@ -1,11 +1,11 @@ -=== +--- + Symbol: TestStruct.Method /TEST_OUTPUT/workspace/clean.go Kind: Method Container Name: github.com/isaacphi/mcp-language-server/integrationtests/test-output/go/workspace -Start Position: Line 12, Column 1 -End Position: Line 14, Column 2 -=== +Range: L12:C1 - L14:C2 + 12|func (t *TestStruct) Method() string { 13| return t.Name 14|} diff --git a/integrationtests/fixtures/snapshots/go/definition/not-found.snap b/integrationtests/fixtures/snapshots/go/definition/not-found.snap new file mode 100644 index 0000000..1f0c9df --- /dev/null +++ b/integrationtests/fixtures/snapshots/go/definition/not-found.snap @@ -0,0 +1 @@ +NotFound not found \ No newline at end of file diff --git a/integrationtests/fixtures/snapshots/go/definition/struct.snap b/integrationtests/fixtures/snapshots/go/definition/struct.snap index 5b87ae0..4fbb2e0 100644 --- a/integrationtests/fixtures/snapshots/go/definition/struct.snap +++ b/integrationtests/fixtures/snapshots/go/definition/struct.snap @@ -1,11 +1,11 @@ -=== +--- + Symbol: TestStruct /TEST_OUTPUT/workspace/clean.go Kind: Struct Container Name: github.com/isaacphi/mcp-language-server/integrationtests/test-output/go/workspace -Start Position: Line 6, Column 1 -End Position: Line 9, Column 2 -=== +Range: L6:C1 - L9:C2 + 6|type TestStruct struct { 7| Name string 8| Age int diff --git a/integrationtests/fixtures/snapshots/go/definition/type.snap b/integrationtests/fixtures/snapshots/go/definition/type.snap index 2374041..66849d2 100644 --- a/integrationtests/fixtures/snapshots/go/definition/type.snap +++ b/integrationtests/fixtures/snapshots/go/definition/type.snap @@ -1,10 +1,10 @@ -=== +--- + Symbol: TestType /TEST_OUTPUT/workspace/clean.go Kind: Class Container Name: github.com/isaacphi/mcp-language-server/integrationtests/test-output/go/workspace -Start Position: Line 22, Column 1 -End Position: Line 22, Column 21 -=== +Range: L22:C1 - L22:C21 + 22|type TestType string diff --git a/integrationtests/fixtures/snapshots/go/definition/variable.snap b/integrationtests/fixtures/snapshots/go/definition/variable.snap index 400e4fc..030f41a 100644 --- a/integrationtests/fixtures/snapshots/go/definition/variable.snap +++ b/integrationtests/fixtures/snapshots/go/definition/variable.snap @@ -1,10 +1,10 @@ -=== +--- + Symbol: TestVariable /TEST_OUTPUT/workspace/clean.go Kind: Variable Container Name: github.com/isaacphi/mcp-language-server/integrationtests/test-output/go/workspace -Start Position: Line 28, Column 1 -End Position: Line 28, Column 22 -=== +Range: L28:C1 - L28:C22 + 28|var TestVariable = 42 diff --git a/integrationtests/fixtures/snapshots/go/diagnostics/dependency.snap b/integrationtests/fixtures/snapshots/go/diagnostics/dependency.snap index 1b8059b..d23a158 100644 --- a/integrationtests/fixtures/snapshots/go/diagnostics/dependency.snap +++ b/integrationtests/fixtures/snapshots/go/diagnostics/dependency.snap @@ -1,5 +1,3 @@ ---- - /TEST_OUTPUT/workspace/consumer.go Diagnostics in File: 1 ERROR at L7:C28: not enough arguments in call to HelperFunction diff --git a/integrationtests/fixtures/snapshots/go/diagnostics/unreachable.snap b/integrationtests/fixtures/snapshots/go/diagnostics/unreachable.snap index ca07c91..69ad1ca 100644 --- a/integrationtests/fixtures/snapshots/go/diagnostics/unreachable.snap +++ b/integrationtests/fixtures/snapshots/go/diagnostics/unreachable.snap @@ -1,11 +1,10 @@ ---- - /TEST_OUTPUT/workspace/main.go Diagnostics in File: 2 WARNING at L8:C2: unreachable code (Source: unreachable, Code: default) -ERROR at L9:C1: missing return (Source: compiler, Code: MissingReturn) +ERROR at L9:C9: cannot use 3 (untyped int constant) as string value in return statement (Source: compiler, Code: IncompatibleAssign) 6|func FooBar() string { 7| return "Hello, World!" 8| fmt.Println("Unreachable code") // This is unreachable code - 9|} + 9| return 3 +10|} diff --git a/integrationtests/fixtures/snapshots/go/references/foobar-function.snap b/integrationtests/fixtures/snapshots/go/references/foobar-function.snap index addef4d..3ca23ee 100644 --- a/integrationtests/fixtures/snapshots/go/references/foobar-function.snap +++ b/integrationtests/fixtures/snapshots/go/references/foobar-function.snap @@ -2,8 +2,8 @@ /TEST_OUTPUT/workspace/main.go References in File: 1 -At: L12:C14 +At: L13:C14 -11|func main() { -12| fmt.Println(FooBar()) -13|} +12|func main() { +13| fmt.Println(FooBar()) +14|} diff --git a/integrationtests/fixtures/snapshots/go/references/not-found.snap b/integrationtests/fixtures/snapshots/go/references/not-found.snap new file mode 100644 index 0000000..fa0a553 --- /dev/null +++ b/integrationtests/fixtures/snapshots/go/references/not-found.snap @@ -0,0 +1 @@ +No references found for symbol: NotFound \ No newline at end of file diff --git a/integrationtests/fixtures/snapshots/go/rename_symbol/successful.snap b/integrationtests/fixtures/snapshots/go/rename_symbol/successful.snap index f9d03cc..9bae4aa 100644 --- a/integrationtests/fixtures/snapshots/go/rename_symbol/successful.snap +++ b/integrationtests/fixtures/snapshots/go/rename_symbol/successful.snap @@ -1,2 +1,5 @@ Successfully renamed symbol to 'UpdatedConstant'. -Updated 4 occurrences across 3 files. \ No newline at end of file +Updated 4 occurrences across 3 files: +/TEST_OUTPUT/workspace/another_consumer.go: L15:C23 +/TEST_OUTPUT/workspace/consumer.go: L15:C23 +/TEST_OUTPUT/workspace/types.go: L24:C4, L25:C7 diff --git a/integrationtests/fixtures/snapshots/go/text_edit/append_to_end_of_file.snap b/integrationtests/fixtures/snapshots/go/text_edit/append_to_end_of_file.snap new file mode 100644 index 0000000..434c338 --- /dev/null +++ b/integrationtests/fixtures/snapshots/go/text_edit/append_to_end_of_file.snap @@ -0,0 +1 @@ +Successfully applied text edits. 1 lines removed, 6 lines added. \ No newline at end of file diff --git a/integrationtests/fixtures/snapshots/go/text_edit/append_to_file.snap b/integrationtests/fixtures/snapshots/go/text_edit/append_to_file.snap deleted file mode 100644 index 1aaba42..0000000 --- a/integrationtests/fixtures/snapshots/go/text_edit/append_to_file.snap +++ /dev/null @@ -1,2 +0,0 @@ -Successfully applied text edits. -WARNING: line numbers may have changed. Re-read code before applying additional edits. \ No newline at end of file diff --git a/integrationtests/fixtures/snapshots/go/text_edit/delete_line.snap b/integrationtests/fixtures/snapshots/go/text_edit/delete_line.snap index 1aaba42..0bc6279 100644 --- a/integrationtests/fixtures/snapshots/go/text_edit/delete_line.snap +++ b/integrationtests/fixtures/snapshots/go/text_edit/delete_line.snap @@ -1,2 +1 @@ -Successfully applied text edits. -WARNING: line numbers may have changed. Re-read code before applying additional edits. \ No newline at end of file +Successfully applied text edits. 1 lines removed, 0 lines added. \ No newline at end of file diff --git a/integrationtests/fixtures/snapshots/go/text_edit/edit_empty_function.snap b/integrationtests/fixtures/snapshots/go/text_edit/edit_empty_function.snap index 1aaba42..7e026ad 100644 --- a/integrationtests/fixtures/snapshots/go/text_edit/edit_empty_function.snap +++ b/integrationtests/fixtures/snapshots/go/text_edit/edit_empty_function.snap @@ -1,2 +1 @@ -Successfully applied text edits. -WARNING: line numbers may have changed. Re-read code before applying additional edits. \ No newline at end of file +Successfully applied text edits. 2 lines removed, 3 lines added. \ No newline at end of file diff --git a/integrationtests/fixtures/snapshots/go/text_edit/edit_single_line_function.snap b/integrationtests/fixtures/snapshots/go/text_edit/edit_single_line_function.snap index 1aaba42..87170b3 100644 --- a/integrationtests/fixtures/snapshots/go/text_edit/edit_single_line_function.snap +++ b/integrationtests/fixtures/snapshots/go/text_edit/edit_single_line_function.snap @@ -1,2 +1 @@ -Successfully applied text edits. -WARNING: line numbers may have changed. Re-read code before applying additional edits. \ No newline at end of file +Successfully applied text edits. 1 lines removed, 3 lines added. \ No newline at end of file diff --git a/integrationtests/fixtures/snapshots/go/text_edit/insert_at_a_line_(by_replacing_it_and_including_original_content).snap b/integrationtests/fixtures/snapshots/go/text_edit/insert_at_a_line_(by_replacing_it_and_including_original_content).snap new file mode 100644 index 0000000..13051d6 --- /dev/null +++ b/integrationtests/fixtures/snapshots/go/text_edit/insert_at_a_line_(by_replacing_it_and_including_original_content).snap @@ -0,0 +1 @@ +Successfully applied text edits. 1 lines removed, 2 lines added. \ No newline at end of file diff --git a/integrationtests/fixtures/snapshots/go/text_edit/insert_line.snap b/integrationtests/fixtures/snapshots/go/text_edit/insert_line.snap deleted file mode 100644 index 1aaba42..0000000 --- a/integrationtests/fixtures/snapshots/go/text_edit/insert_line.snap +++ /dev/null @@ -1,2 +0,0 @@ -Successfully applied text edits. -WARNING: line numbers may have changed. Re-read code before applying additional edits. \ No newline at end of file diff --git a/integrationtests/fixtures/snapshots/go/text_edit/multiple_edits.snap b/integrationtests/fixtures/snapshots/go/text_edit/multiple_edits.snap deleted file mode 100644 index 1aaba42..0000000 --- a/integrationtests/fixtures/snapshots/go/text_edit/multiple_edits.snap +++ /dev/null @@ -1,2 +0,0 @@ -Successfully applied text edits. -WARNING: line numbers may have changed. Re-read code before applying additional edits. \ No newline at end of file diff --git a/integrationtests/fixtures/snapshots/go/text_edit/multiple_edits_in_same_file.snap b/integrationtests/fixtures/snapshots/go/text_edit/multiple_edits_in_same_file.snap new file mode 100644 index 0000000..11ce75e --- /dev/null +++ b/integrationtests/fixtures/snapshots/go/text_edit/multiple_edits_in_same_file.snap @@ -0,0 +1 @@ +Successfully applied text edits. 2 lines removed, 2 lines added. \ No newline at end of file diff --git a/integrationtests/fixtures/snapshots/go/text_edit/replace_multiple_lines.snap b/integrationtests/fixtures/snapshots/go/text_edit/replace_multiple_lines.snap index 1aaba42..7579b69 100644 --- a/integrationtests/fixtures/snapshots/go/text_edit/replace_multiple_lines.snap +++ b/integrationtests/fixtures/snapshots/go/text_edit/replace_multiple_lines.snap @@ -1,2 +1 @@ -Successfully applied text edits. -WARNING: line numbers may have changed. Re-read code before applying additional edits. \ No newline at end of file +Successfully applied text edits. 4 lines removed, 4 lines added. \ No newline at end of file diff --git a/integrationtests/fixtures/snapshots/go/text_edit/replace_single_line.snap b/integrationtests/fixtures/snapshots/go/text_edit/replace_single_line.snap index 1aaba42..030930c 100644 --- a/integrationtests/fixtures/snapshots/go/text_edit/replace_single_line.snap +++ b/integrationtests/fixtures/snapshots/go/text_edit/replace_single_line.snap @@ -1,2 +1 @@ -Successfully applied text edits. -WARNING: line numbers may have changed. Re-read code before applying additional edits. \ No newline at end of file +Successfully applied text edits. 1 lines removed, 1 lines added. \ No newline at end of file diff --git a/integrationtests/fixtures/snapshots/python/definition/class.snap b/integrationtests/fixtures/snapshots/python/definition/class.snap index 3c2992d..6661005 100644 --- a/integrationtests/fixtures/snapshots/python/definition/class.snap +++ b/integrationtests/fixtures/snapshots/python/definition/class.snap @@ -1,10 +1,10 @@ -=== +--- + Symbol: TestClass /TEST_OUTPUT/workspace/main.py Kind: Class -Start Position: Line 18, Column 1 -End Position: Line 59, Column 22 -=== +Range: L18:C1 - L59:C22 + 18|class TestClass: 19| """A test class with methods and attributes.""" 20| diff --git a/integrationtests/fixtures/snapshots/python/definition/constant.snap b/integrationtests/fixtures/snapshots/python/definition/constant.snap index 0d9f2bb..d22fb63 100644 --- a/integrationtests/fixtures/snapshots/python/definition/constant.snap +++ b/integrationtests/fixtures/snapshots/python/definition/constant.snap @@ -1,9 +1,9 @@ -=== +--- + Symbol: TEST_CONSTANT /TEST_OUTPUT/workspace/main.py Kind: Constant -Start Position: Line 79, Column 1 -End Position: Line 79, Column 14 -=== +Range: L79:C1 - L79:C14 + 79|TEST_CONSTANT: str = "test constant" diff --git a/integrationtests/fixtures/snapshots/python/definition/derived-class.snap b/integrationtests/fixtures/snapshots/python/definition/derived-class.snap index 61ca818..7b0a098 100644 --- a/integrationtests/fixtures/snapshots/python/definition/derived-class.snap +++ b/integrationtests/fixtures/snapshots/python/definition/derived-class.snap @@ -1,10 +1,10 @@ -=== +--- + Symbol: DerivedClass /TEST_OUTPUT/workspace/main.py Kind: Class -Start Position: Line 70, Column 1 -End Position: Line 75, Column 13 -=== +Range: L70:C1 - L75:C13 + 70|class DerivedClass(BaseClass): 71| """A class that inherits from BaseClass.""" 72| diff --git a/integrationtests/fixtures/snapshots/python/definition/function.snap b/integrationtests/fixtures/snapshots/python/definition/function.snap index 46da10c..7b831ec 100644 --- a/integrationtests/fixtures/snapshots/python/definition/function.snap +++ b/integrationtests/fixtures/snapshots/python/definition/function.snap @@ -1,10 +1,10 @@ -=== +--- + Symbol: test_function /TEST_OUTPUT/workspace/main.py Kind: Function -Start Position: Line 6, Column 1 -End Position: Line 15, Column 29 -=== +Range: L6:C1 - L15:C29 + 6|def test_function(name: str) -> str: 7| """A simple test function that returns a greeting message. 8| diff --git a/integrationtests/fixtures/snapshots/python/definition/method.snap b/integrationtests/fixtures/snapshots/python/definition/method.snap index e993c44..00806d8 100644 --- a/integrationtests/fixtures/snapshots/python/definition/method.snap +++ b/integrationtests/fixtures/snapshots/python/definition/method.snap @@ -1,11 +1,11 @@ -=== +--- + Symbol: test_method /TEST_OUTPUT/workspace/main.py Kind: Method Container Name: TestClass -Start Position: Line 18, Column 1 -End Position: Line 59, Column 22 -=== +Range: L18:C1 - L59:C22 + 18|class TestClass: 19| """A test class with methods and attributes.""" 20| diff --git a/integrationtests/fixtures/snapshots/python/definition/same-name.snap b/integrationtests/fixtures/snapshots/python/definition/same-name.snap new file mode 100644 index 0000000..80a5351 --- /dev/null +++ b/integrationtests/fixtures/snapshots/python/definition/same-name.snap @@ -0,0 +1,20 @@ +--- + +Symbol: SameName +/TEST_OUTPUT/workspace/clean.py +Kind: Function +Range: L6:C1 - L7:C9 + +6|def SameName(): +7| pass + +--- + +Symbol: SameName +/TEST_OUTPUT/workspace/helper.py +Kind: Class +Range: L24:C1 - L25:C9 + +24|class SameName: +25| pass + diff --git a/integrationtests/fixtures/snapshots/python/definition/static-method.snap b/integrationtests/fixtures/snapshots/python/definition/static-method.snap index 7aa5ca6..d29faf4 100644 --- a/integrationtests/fixtures/snapshots/python/definition/static-method.snap +++ b/integrationtests/fixtures/snapshots/python/definition/static-method.snap @@ -1,11 +1,11 @@ -=== +--- + Symbol: static_method /TEST_OUTPUT/workspace/main.py Kind: Method Container Name: TestClass -Start Position: Line 18, Column 1 -End Position: Line 59, Column 22 -=== +Range: L18:C1 - L59:C22 + 18|class TestClass: 19| """A test class with methods and attributes.""" 20| diff --git a/integrationtests/fixtures/snapshots/python/definition/variable.snap b/integrationtests/fixtures/snapshots/python/definition/variable.snap index 451228a..8ea6bb6 100644 --- a/integrationtests/fixtures/snapshots/python/definition/variable.snap +++ b/integrationtests/fixtures/snapshots/python/definition/variable.snap @@ -1,9 +1,9 @@ -=== +--- + Symbol: test_variable /TEST_OUTPUT/workspace/main.py Kind: Variable -Start Position: Line 83, Column 1 -End Position: Line 83, Column 14 -=== +Range: L83:C1 - L83:C14 + 83|test_variable: list[int] = [1, 2, 3, 4, 5] diff --git a/integrationtests/fixtures/snapshots/python/diagnostics/dependency.snap b/integrationtests/fixtures/snapshots/python/diagnostics/dependency.snap index da1e997..afcbd03 100644 --- a/integrationtests/fixtures/snapshots/python/diagnostics/dependency.snap +++ b/integrationtests/fixtures/snapshots/python/diagnostics/dependency.snap @@ -1,5 +1,3 @@ ---- - /TEST_OUTPUT/workspace/consumer_clean.py Diagnostics in File: 1 ERROR at L9:C15: Argument missing for parameter "age" (Source: Pyright, Code: reportCallIssue) diff --git a/integrationtests/fixtures/snapshots/python/diagnostics/errors.snap b/integrationtests/fixtures/snapshots/python/diagnostics/errors.snap index 4c2e62f..6d9df05 100644 --- a/integrationtests/fixtures/snapshots/python/diagnostics/errors.snap +++ b/integrationtests/fixtures/snapshots/python/diagnostics/errors.snap @@ -1,5 +1,3 @@ ---- - /TEST_OUTPUT/workspace/error_file.py Diagnostics in File: 3 ERROR at L31:C12: Type "Literal[42]" is not assignable to return type "str" diff --git a/integrationtests/fixtures/snapshots/python/rename_symbol/successful.snap b/integrationtests/fixtures/snapshots/python/rename_symbol/successful.snap index eaec313..df27c41 100644 --- a/integrationtests/fixtures/snapshots/python/rename_symbol/successful.snap +++ b/integrationtests/fixtures/snapshots/python/rename_symbol/successful.snap @@ -1,2 +1,5 @@ Successfully renamed symbol to 'UPDATED_CONSTANT'. -Updated 6 occurrences across 3 files. \ No newline at end of file +Updated 6 occurrences across 3 files: +/TEST_OUTPUT/workspace/another_consumer.py: L4:C5, L16:C51, L34:C30 +/TEST_OUTPUT/workspace/consumer.py: L8:C5, L46:C43 +/TEST_OUTPUT/workspace/helper.py: L8:C1 diff --git a/integrationtests/fixtures/snapshots/rust/definition/constant.snap b/integrationtests/fixtures/snapshots/rust/definition/constant.snap index 29fc8a3..5c210f7 100644 --- a/integrationtests/fixtures/snapshots/rust/definition/constant.snap +++ b/integrationtests/fixtures/snapshots/rust/definition/constant.snap @@ -1,10 +1,10 @@ -=== +--- + Symbol: TEST_CONSTANT /TEST_OUTPUT/workspace/src/types.rs Kind: Constant -Start Position: Line 3, Column 1 -End Position: Line 4, Column 55 -=== +Range: L3:C1 - L4:C55 + 3|// A simple constant 4|pub const TEST_CONSTANT: &str = "test constant value"; diff --git a/integrationtests/fixtures/snapshots/rust/definition/foobar.snap b/integrationtests/fixtures/snapshots/rust/definition/foobar.snap index 876a14d..73051eb 100644 --- a/integrationtests/fixtures/snapshots/rust/definition/foobar.snap +++ b/integrationtests/fixtures/snapshots/rust/definition/foobar.snap @@ -1,10 +1,10 @@ -=== +--- + Symbol: foo_bar /TEST_OUTPUT/workspace/src/main.rs Kind: Function -Start Position: Line 8, Column 1 -End Position: Line 12, Column 2 -=== +Range: L8:C1 - L12:C2 + 8|// FooBar is a simple function for testing 9|fn foo_bar() -> String { 10| String::from("Hello, World!") diff --git a/integrationtests/fixtures/snapshots/rust/definition/function.snap b/integrationtests/fixtures/snapshots/rust/definition/function.snap index 411961a..820a293 100644 --- a/integrationtests/fixtures/snapshots/rust/definition/function.snap +++ b/integrationtests/fixtures/snapshots/rust/definition/function.snap @@ -1,10 +1,10 @@ -=== +--- + Symbol: test_function /TEST_OUTPUT/workspace/src/types.rs Kind: Function -Start Position: Line 80, Column 1 -End Position: Line 83, Column 2 -=== +Range: L80:C1 - L83:C2 + 80|// A simple function for testing 81|pub fn test_function() -> String { 82| String::from("test function") diff --git a/integrationtests/fixtures/snapshots/rust/definition/interface.snap b/integrationtests/fixtures/snapshots/rust/definition/interface.snap index 7f68a37..9ddd8a0 100644 --- a/integrationtests/fixtures/snapshots/rust/definition/interface.snap +++ b/integrationtests/fixtures/snapshots/rust/definition/interface.snap @@ -1,10 +1,10 @@ -=== +--- + Symbol: TestInterface /TEST_OUTPUT/workspace/src/types.rs Kind: Interface -Start Position: Line 32, Column 1 -End Position: Line 36, Column 2 -=== +Range: L32:C1 - L36:C2 + 32|// An interface (trait) for testing 33|pub trait TestInterface { 34| fn get_name(&self) -> String; diff --git a/integrationtests/fixtures/snapshots/rust/definition/method.snap b/integrationtests/fixtures/snapshots/rust/definition/method.snap index d84ac14..b661954 100644 --- a/integrationtests/fixtures/snapshots/rust/definition/method.snap +++ b/integrationtests/fixtures/snapshots/rust/definition/method.snap @@ -1,11 +1,11 @@ -=== +--- + Symbol: method /TEST_OUTPUT/workspace/src/types.rs Kind: Function Container Name: TestStruct -Start Position: Line 18, Column 1 -End Position: Line 30, Column 2 -=== +Range: L18:C1 - L30:C2 + 18|// Implementation for TestStruct 19|impl TestStruct { 20| pub fn new(name: &str, value: i32) -> Self { @@ -20,14 +20,14 @@ End Position: Line 30, Column 2 29| } 30|} -=== +--- + Symbol: method /TEST_OUTPUT/workspace/src/types.rs Kind: Function Container Name: SharedStruct -Start Position: Line 54, Column 1 -End Position: Line 64, Column 2 -=== +Range: L54:C1 - L64:C2 + 54|impl SharedStruct { 55| pub fn new(name: &str) -> Self { 56| SharedStruct { diff --git a/integrationtests/fixtures/snapshots/rust/definition/struct.snap b/integrationtests/fixtures/snapshots/rust/definition/struct.snap index a8f241b..123f7fb 100644 --- a/integrationtests/fixtures/snapshots/rust/definition/struct.snap +++ b/integrationtests/fixtures/snapshots/rust/definition/struct.snap @@ -1,10 +1,10 @@ -=== +--- + Symbol: TestStruct /TEST_OUTPUT/workspace/src/types.rs Kind: Struct -Start Position: Line 12, Column 1 -End Position: Line 16, Column 2 -=== +Range: L12:C1 - L16:C2 + 12|// A struct for testing 13|pub struct TestStruct { 14| pub name: String, diff --git a/integrationtests/fixtures/snapshots/rust/definition/type.snap b/integrationtests/fixtures/snapshots/rust/definition/type.snap index 970ec4e..44b655d 100644 --- a/integrationtests/fixtures/snapshots/rust/definition/type.snap +++ b/integrationtests/fixtures/snapshots/rust/definition/type.snap @@ -1,10 +1,10 @@ -=== +--- + Symbol: TestType /TEST_OUTPUT/workspace/src/types.rs Kind: TypeParameter -Start Position: Line 9, Column 1 -End Position: Line 10, Column 28 -=== +Range: L9:C1 - L10:C28 + 9|// A simple type alias 10|pub type TestType = String; diff --git a/integrationtests/fixtures/snapshots/rust/definition/variable.snap b/integrationtests/fixtures/snapshots/rust/definition/variable.snap index b0e0ca3..5a4861b 100644 --- a/integrationtests/fixtures/snapshots/rust/definition/variable.snap +++ b/integrationtests/fixtures/snapshots/rust/definition/variable.snap @@ -1,10 +1,10 @@ -=== +--- + Symbol: TEST_VARIABLE /TEST_OUTPUT/workspace/src/types.rs Kind: Constant -Start Position: Line 6, Column 1 -End Position: Line 7, Column 56 -=== +Range: L6:C1 - L7:C56 + 6|// A simple variable 7|pub static TEST_VARIABLE: &str = "test variable value"; diff --git a/integrationtests/fixtures/snapshots/rust/diagnostics/dependency.snap b/integrationtests/fixtures/snapshots/rust/diagnostics/dependency.snap index c10283a..e3b9a32 100644 --- a/integrationtests/fixtures/snapshots/rust/diagnostics/dependency.snap +++ b/integrationtests/fixtures/snapshots/rust/diagnostics/dependency.snap @@ -1,5 +1,3 @@ ---- - /TEST_OUTPUT/workspace/src/consumer.rs Diagnostics in File: 1 ERROR at L9:C33: expected 1 argument, found 0 (Source: rust-analyzer, Code: E0107) diff --git a/integrationtests/fixtures/snapshots/rust/diagnostics/unreachable.snap b/integrationtests/fixtures/snapshots/rust/diagnostics/unreachable.snap index 95305f6..12f2fe4 100644 --- a/integrationtests/fixtures/snapshots/rust/diagnostics/unreachable.snap +++ b/integrationtests/fixtures/snapshots/rust/diagnostics/unreachable.snap @@ -1,5 +1,3 @@ ---- - /TEST_OUTPUT/workspace/src/main.rs Diagnostics in File: 6 ERROR at L10:C34: Syntax Error: expected SEMICOLON (Source: rust-analyzer, Code: syntax-error) diff --git a/integrationtests/fixtures/snapshots/rust/rename_symbol/successful.snap b/integrationtests/fixtures/snapshots/rust/rename_symbol/successful.snap index 7115d23..b789099 100644 --- a/integrationtests/fixtures/snapshots/rust/rename_symbol/successful.snap +++ b/integrationtests/fixtures/snapshots/rust/rename_symbol/successful.snap @@ -1,2 +1,5 @@ Successfully renamed symbol to 'UPDATED_CONSTANT'. -Updated 5 occurrences across 3 files. \ No newline at end of file +Updated 5 occurrences across 3 files: +/TEST_OUTPUT/workspace/src/another_consumer.rs: L4:C48, L20:C50 +/TEST_OUTPUT/workspace/src/consumer.rs: L4:C48, L21:C30 +/TEST_OUTPUT/workspace/src/types.rs: L78:C11 diff --git a/integrationtests/fixtures/snapshots/typescript/definition/class.snap b/integrationtests/fixtures/snapshots/typescript/definition/class.snap index fadcfdf..d8f3880 100644 --- a/integrationtests/fixtures/snapshots/typescript/definition/class.snap +++ b/integrationtests/fixtures/snapshots/typescript/definition/class.snap @@ -1,17 +1,17 @@ -=== +--- + Symbol: TestClass /TEST_OUTPUT/workspace/main.ts Kind: Class -Start Position: Line 14, Column 1 -End Position: Line 24, Column 2 -=== +Range: L14:C1 - L24:C2 + 14|export class TestClass implements TestInterface { 15| property: string; -16| +16| 17| constructor() { 18| this.property = "test"; 19| } -20| +20| 21| method(): void { 22| console.log("Method called"); 23| } diff --git a/integrationtests/fixtures/snapshots/typescript/definition/constant.snap b/integrationtests/fixtures/snapshots/typescript/definition/constant.snap index 1d35994..95b04ab 100644 --- a/integrationtests/fixtures/snapshots/typescript/definition/constant.snap +++ b/integrationtests/fixtures/snapshots/typescript/definition/constant.snap @@ -1,9 +1,9 @@ -=== +--- + Symbol: TestConstant /TEST_OUTPUT/workspace/main.ts Kind: Constant -Start Position: Line 33, Column 1 -End Position: Line 33, Column 31 -=== +Range: L33:C1 - L33:C31 + 33|export const TestConstant = 42; diff --git a/integrationtests/fixtures/snapshots/typescript/definition/function.snap b/integrationtests/fixtures/snapshots/typescript/definition/function.snap index 1051942..fe2e413 100644 --- a/integrationtests/fixtures/snapshots/typescript/definition/function.snap +++ b/integrationtests/fixtures/snapshots/typescript/definition/function.snap @@ -1,10 +1,10 @@ -=== +--- + Symbol: TestFunction /TEST_OUTPUT/workspace/main.ts Kind: Function -Start Position: Line 2, Column 1 -End Position: Line 5, Column 2 -=== +Range: L2:C1 - L5:C2 + 2|export function TestFunction(): string { 3| return "Hello, World!"; 4| console.log("Unreachable code"); // This is unreachable code diff --git a/integrationtests/fixtures/snapshots/typescript/definition/interface.snap b/integrationtests/fixtures/snapshots/typescript/definition/interface.snap index 3992e86..7dc06da 100644 --- a/integrationtests/fixtures/snapshots/typescript/definition/interface.snap +++ b/integrationtests/fixtures/snapshots/typescript/definition/interface.snap @@ -1,10 +1,10 @@ -=== +--- + Symbol: TestInterface /TEST_OUTPUT/workspace/main.ts Kind: Interface -Start Position: Line 8, Column 1 -End Position: Line 11, Column 2 -=== +Range: L8:C1 - L11:C2 + 8|export interface TestInterface { 9| method(): void; 10| property: string; diff --git a/integrationtests/fixtures/snapshots/typescript/definition/type.snap b/integrationtests/fixtures/snapshots/typescript/definition/type.snap index 4406c38..bed0b11 100644 --- a/integrationtests/fixtures/snapshots/typescript/definition/type.snap +++ b/integrationtests/fixtures/snapshots/typescript/definition/type.snap @@ -1,9 +1,9 @@ -=== +--- + Symbol: TestType /TEST_OUTPUT/workspace/main.ts Kind: Variable -Start Position: Line 27, Column 1 -End Position: Line 27, Column 40 -=== +Range: L27:C1 - L27:C40 + 27|export type TestType = string | number; diff --git a/integrationtests/fixtures/snapshots/typescript/definition/variable.snap b/integrationtests/fixtures/snapshots/typescript/definition/variable.snap index ff4f996..ba0b623 100644 --- a/integrationtests/fixtures/snapshots/typescript/definition/variable.snap +++ b/integrationtests/fixtures/snapshots/typescript/definition/variable.snap @@ -1,9 +1,9 @@ -=== +--- + Symbol: TestVariable /TEST_OUTPUT/workspace/main.ts Kind: Constant -Start Position: Line 30, Column 1 -End Position: Line 30, Column 43 -=== +Range: L30:C1 - L30:C43 + 30|export const TestVariable: string = "Test"; diff --git a/integrationtests/fixtures/snapshots/typescript/diagnostics/dependency.snap b/integrationtests/fixtures/snapshots/typescript/diagnostics/dependency.snap index 8fc60f4..611e451 100644 --- a/integrationtests/fixtures/snapshots/typescript/diagnostics/dependency.snap +++ b/integrationtests/fixtures/snapshots/typescript/diagnostics/dependency.snap @@ -1,5 +1,3 @@ ---- - /TEST_OUTPUT/workspace/consumer.ts Diagnostics in File: 1 ERROR at L13:C36: Expected 1 arguments, but got 0. (Source: typescript, Code: 2554) diff --git a/integrationtests/fixtures/snapshots/typescript/diagnostics/type-error.snap b/integrationtests/fixtures/snapshots/typescript/diagnostics/type-error.snap index 67fc56a..9c5e4fa 100644 --- a/integrationtests/fixtures/snapshots/typescript/diagnostics/type-error.snap +++ b/integrationtests/fixtures/snapshots/typescript/diagnostics/type-error.snap @@ -1,5 +1,3 @@ ---- - /TEST_OUTPUT/workspace/error.ts Diagnostics in File: 1 ERROR at L4:C3: Type 'number' is not assignable to type 'string'. (Source: typescript, Code: 2322) diff --git a/integrationtests/fixtures/snapshots/typescript/rename_symbol/successful.snap b/integrationtests/fixtures/snapshots/typescript/rename_symbol/successful.snap index 3181da3..d74e438 100644 --- a/integrationtests/fixtures/snapshots/typescript/rename_symbol/successful.snap +++ b/integrationtests/fixtures/snapshots/typescript/rename_symbol/successful.snap @@ -1,2 +1,5 @@ Successfully renamed symbol to 'UpdatedConstant'. -Updated 5 occurrences across 3 files. \ No newline at end of file +Updated 5 occurrences across 3 files: +/TEST_OUTPUT/workspace/another_consumer.ts: L7:C3, L29:C30 +/TEST_OUTPUT/workspace/consumer.ts: L7:C3, L31:C15 +/TEST_OUTPUT/workspace/helper.ts: L39:C14 diff --git a/integrationtests/languages/go/definition/definition_test.go b/integrationtests/languages/go/definition/definition_test.go index 8d66d6c..884d672 100644 --- a/integrationtests/languages/go/definition/definition_test.go +++ b/integrationtests/languages/go/definition/definition_test.go @@ -72,6 +72,12 @@ func TestReadDefinition(t *testing.T) { expectedText: "func TestFunction()", snapshotName: "function", }, + { + name: "NotFound", + symbolName: "NotFound", + expectedText: "not found", + snapshotName: "not-found", + }, } for _, tc := range tests { diff --git a/integrationtests/languages/go/references/references_test.go b/integrationtests/languages/go/references/references_test.go index 441aab2..8a22d71 100644 --- a/integrationtests/languages/go/references/references_test.go +++ b/integrationtests/languages/go/references/references_test.go @@ -82,6 +82,13 @@ func TestFindReferences(t *testing.T) { expectedFiles: 2, // consumer.go and another_consumer.go snapshotName: "shared-type", }, + { + name: "References not found", + symbolName: "NotFound", + expectedText: "No references found for symbol:", + expectedFiles: 0, + snapshotName: "not-found", + }, } for _, tc := range tests { diff --git a/integrationtests/languages/go/text_edit/text_edit_test.go b/integrationtests/languages/go/text_edit/text_edit_test.go index 3334859..dfab657 100644 --- a/integrationtests/languages/go/text_edit/text_edit_test.go +++ b/integrationtests/languages/go/text_edit/text_edit_test.go @@ -7,6 +7,7 @@ import ( "testing" "time" + "github.com/isaacphi/mcp-language-server/integrationtests/languages/common" "github.com/isaacphi/mcp-language-server/integrationtests/languages/go/internal" "github.com/isaacphi/mcp-language-server/internal/tools" ) @@ -191,6 +192,10 @@ func AnotherFunction() { for _, verify := range tc.verifications { verify(t, content) } + + // Use snapshot testing to verify the exact result + snapshotName := strings.ToLower(strings.ReplaceAll(tc.name, " ", "_")) + common.SnapshotTest(t, "go", "text_edit", snapshotName, result) }) } } @@ -335,6 +340,10 @@ func NewFunction() { for _, verify := range tc.verifications { verify(t, content) } + + // Use snapshot testing to verify the exact result + snapshotName := strings.ToLower(strings.ReplaceAll(tc.name, " ", "_")) + common.SnapshotTest(t, "go", "text_edit", snapshotName, result) }) } } diff --git a/integrationtests/languages/python/definition/definition_test.go b/integrationtests/languages/python/definition/definition_test.go index f32da2c..48b6992 100644 --- a/integrationtests/languages/python/definition/definition_test.go +++ b/integrationtests/languages/python/definition/definition_test.go @@ -69,6 +69,12 @@ func TestReadDefinition(t *testing.T) { expectedText: "class DerivedClass", snapshotName: "derived-class", }, + { + name: "MultipleFiles", + symbolName: "SameName", + expectedText: "class SameName", + snapshotName: "same-name", + }, } for _, tc := range tests { diff --git a/integrationtests/workspaces/go/main.go b/integrationtests/workspaces/go/main.go index 5733d9e..289af3f 100644 --- a/integrationtests/workspaces/go/main.go +++ b/integrationtests/workspaces/go/main.go @@ -6,6 +6,7 @@ import "fmt" func FooBar() string { return "Hello, World!" fmt.Println("Unreachable code") // This is unreachable code + return 3 } func main() { diff --git a/integrationtests/workspaces/python/clean.py b/integrationtests/workspaces/python/clean.py index d8aa858..934c9d2 100644 --- a/integrationtests/workspaces/python/clean.py +++ b/integrationtests/workspaces/python/clean.py @@ -3,6 +3,10 @@ from typing import Optional, Tuple +def SameName(): + pass + + def clean_function(param: str) -> str: """A clean function without errors. diff --git a/integrationtests/workspaces/python/helper.py b/integrationtests/workspaces/python/helper.py index 97d6a1e..1824de4 100644 --- a/integrationtests/workspaces/python/helper.py +++ b/integrationtests/workspaces/python/helper.py @@ -21,6 +21,10 @@ class Color(Enum): T = TypeVar("T") +class SameName: + pass + + # Shared class that will be referenced across files class SharedClass(Generic[T]): """A shared class that is used across multiple files.""" diff --git a/integrationtests/workspaces/typescript/main.ts b/integrationtests/workspaces/typescript/main.ts index 045e490..0c40c90 100644 --- a/integrationtests/workspaces/typescript/main.ts +++ b/integrationtests/workspaces/typescript/main.ts @@ -13,11 +13,11 @@ export interface TestInterface { // TestClass with method export class TestClass implements TestInterface { property: string; - + constructor() { this.property = "test"; } - + method(): void { console.log("Method called"); } @@ -39,4 +39,5 @@ function main() { instance.method(); } -main(); \ No newline at end of file +main(); + diff --git a/internal/tools/apply-text-edit.go b/internal/tools/apply-text-edit.go index 5c712b9..202ae80 100644 --- a/internal/tools/apply-text-edit.go +++ b/internal/tools/apply-text-edit.go @@ -25,6 +25,31 @@ func ApplyTextEdits(ctx context.Context, client *lsp.Client, filePath string, ed return "", fmt.Errorf("could not open file: %v", err) } + // Create a sorted copy of edits for reporting + sortedEdits := make([]TextEdit, len(edits)) + copy(sortedEdits, edits) + sort.Slice(sortedEdits, func(i, j int) bool { + return sortedEdits[i].StartLine < sortedEdits[j].StartLine + }) + + // Track lines added and removed for sorted edits + linesRemovedSorted := 0 + linesAddedSorted := 0 + for _, edit := range sortedEdits { + // Calculate lines removed: end - start + 1 + removedLineCount := edit.EndLine - edit.StartLine + 1 + linesRemovedSorted += removedLineCount + + // Calculate lines added: count newlines in the replacement text + 1 + addedLineCount := 1 + if edit.NewText != "" { + addedLineCount = strings.Count(edit.NewText, "\n") + 1 + } else if edit.NewText == "" { + addedLineCount = 0 + } + linesAddedSorted += addedLineCount + } + // Sort edits by line number in descending order to process from bottom to top // This way line numbers don't shift under us as we make edits sort.Slice(edits, func(i, j int) bool { @@ -40,7 +65,7 @@ func ApplyTextEdits(ctx context.Context, client *lsp.Client, filePath string, ed return "", fmt.Errorf("invalid position: %v", err) } - // Always do a replacement - this simplifies the model and makes behavior predictable + // Always do a replacement textEdits = append(textEdits, protocol.TextEdit{ Range: rng, NewText: edit.NewText, @@ -57,7 +82,7 @@ func ApplyTextEdits(ctx context.Context, client *lsp.Client, filePath string, ed return "", fmt.Errorf("failed to apply text edits: %v", err) } - return "Successfully applied text edits.\nWARNING: line numbers may have changed. Re-read code before applying additional edits.", nil + return fmt.Sprintf("Successfully applied text edits. %d lines removed, %d lines added.", linesRemovedSorted, linesAddedSorted), nil } // getRange creates a protocol.Range that covers the specified start and end lines diff --git a/internal/tools/diagnostics.go b/internal/tools/diagnostics.go index 2c78358..5b96b40 100644 --- a/internal/tools/diagnostics.go +++ b/internal/tools/diagnostics.go @@ -50,7 +50,7 @@ func GetDiagnosticsForFile(ctx context.Context, client *lsp.Client, filePath str } // Format file header - fileInfo := fmt.Sprintf("---\n\n%s\nDiagnostics in File: %d\n", + fileInfo := fmt.Sprintf("%s\nDiagnostics in File: %d\n", filePath, len(diagnostics), ) diff --git a/internal/tools/get-codelens.go b/internal/tools/get-codelens.go index 79d7174..c6f3611 100644 --- a/internal/tools/get-codelens.go +++ b/internal/tools/get-codelens.go @@ -39,8 +39,7 @@ func GetCodeLens(ctx context.Context, client *lsp.Client, filePath string) (stri // Format the code lens results var output strings.Builder - output.WriteString(fmt.Sprintf("Code Lens results for %s:\n", filePath)) - output.WriteString(strings.Repeat("=", 3) + "\n\n") + output.WriteString(fmt.Sprintf("Code Lens results for %s:\n\n", filePath)) for i, lens := range codeLensResult { output.WriteString(fmt.Sprintf("[%d] Location: Lines %d-%d\n", diff --git a/internal/tools/read-definition.go b/internal/tools/read-definition.go index c2bb5c7..004d2d3 100644 --- a/internal/tools/read-definition.go +++ b/internal/tools/read-definition.go @@ -64,23 +64,21 @@ func ReadDefinition(ctx context.Context, client *lsp.Client, symbolName string, toolsLogger.Debug("Found symbol: %s", symbol.GetName()) loc := symbol.GetLocation() - banner := strings.Repeat("=", 3) + "\n" + banner := "---\n\n" definition, loc, err := GetFullDefinition(ctx, client, loc) locationInfo := fmt.Sprintf( "Symbol: %s\n"+ "File: %s\n"+ kind+ container+ - "Start Position: Line %d, Column %d\n"+ - "End Position: Line %d, Column %d\n"+ - "%s\n", + "Range: L%d:C%d - L%d:C%d\n\n", symbol.GetName(), strings.TrimPrefix(string(loc.URI), "file://"), loc.Range.Start.Line+1, loc.Range.Start.Character+1, loc.Range.End.Line+1, loc.Range.End.Character+1, - strings.Repeat("=", 3)) + ) if err != nil { toolsLogger.Error("Error getting definition: %v", err) diff --git a/internal/tools/rename-symbol.go b/internal/tools/rename-symbol.go index c96a9ba..f51e3e7 100644 --- a/internal/tools/rename-symbol.go +++ b/internal/tools/rename-symbol.go @@ -3,6 +3,8 @@ package tools import ( "context" "fmt" + "sort" + "strings" "github.com/isaacphi/mcp-language-server/internal/lsp" "github.com/isaacphi/mcp-language-server/internal/protocol" @@ -47,22 +49,69 @@ func RenameSymbol(ctx context.Context, client *lsp.Client, filePath string, line changeCount := 0 fileCount := 0 + // Build output + var locationsBuilder strings.Builder + + // Create a slice to store all changes before sorting and writing + type FileChanges struct { + URI string + Locations string + } + var allChanges []FileChanges + // Count changes in Changes field if workspaceEdit.Changes != nil { fileCount = len(workspaceEdit.Changes) - for _, edits := range workspaceEdit.Changes { + for uri, edits := range workspaceEdit.Changes { changeCount += len(edits) + var locs strings.Builder + for i, change := range edits { + locs.WriteString( + fmt.Sprintf("L%d:C%d", change.Range.Start.Line+1, change.Range.Start.Character+1), + ) + if i != len(edits)-1 { + locs.WriteString(", ") + } + } + allChanges = append(allChanges, FileChanges{ + URI: string(uri), + Locations: locs.String(), + }) } } // Count changes in DocumentChanges field for _, change := range workspaceEdit.DocumentChanges { if change.TextDocumentEdit != nil { + var locs strings.Builder + for i, edit := range change.TextDocumentEdit.Edits { + textEdit, err := edit.AsTextEdit() + if err == nil { + locs.WriteString(fmt.Sprintf("L%d:C%d", textEdit.Range.Start.Line+1, textEdit.Range.Start.Character+1)) + if i != len(change.TextDocumentEdit.Edits)-1 { + locs.WriteString(", ") + } + } + } + allChanges = append(allChanges, FileChanges{ + URI: string(change.TextDocumentEdit.TextDocument.URI), + Locations: locs.String(), + }) fileCount++ changeCount += len(change.TextDocumentEdit.Edits) } } + // Sort changes by filename for consistent output + sort.Slice(allChanges, func(i, j int) bool { + return allChanges[i].URI < allChanges[j].URI + }) + + // Write sorted changes to the output builder + for _, change := range allChanges { + locationsBuilder.WriteString(fmt.Sprintf("%s: %s\n", change.URI, change.Locations)) + } + // Apply the workspace edit to files:workspaceEdit if err := utilities.ApplyWorkspaceEdit(workspaceEdit); err != nil { return "", fmt.Errorf("failed to apply changes: %v", err) @@ -73,6 +122,6 @@ func RenameSymbol(ctx context.Context, client *lsp.Client, filePath string, line } // Generate a summary of changes made - return fmt.Sprintf("Successfully renamed symbol to '%s'.\nUpdated %d occurrences across %d files.", - newName, changeCount, fileCount), nil + return fmt.Sprintf("Successfully renamed symbol to '%s'.\nUpdated %d occurrences across %d files:\n%s", + newName, changeCount, fileCount, locationsBuilder.String()), nil } diff --git a/internal/utilities/edit.go b/internal/utilities/edit.go index 165a6ba..738c2b2 100644 --- a/internal/utilities/edit.go +++ b/internal/utilities/edit.go @@ -7,6 +7,7 @@ import ( "sort" "strings" + "github.com/davecgh/go-spew/spew" "github.com/isaacphi/mcp-language-server/internal/protocol" ) @@ -241,6 +242,7 @@ func ApplyWorkspaceEdit(edit protocol.WorkspaceEdit) error { // Handle DocumentChanges field for _, change := range edit.DocumentChanges { + coreLogger.Warn("Document change: %v", spew.Sdump(change)) if err := ApplyDocumentChange(change); err != nil { return fmt.Errorf("failed to apply document change: %w", err) } diff --git a/internal/utilities/logging.go b/internal/utilities/logging.go new file mode 100644 index 0000000..0337315 --- /dev/null +++ b/internal/utilities/logging.go @@ -0,0 +1,7 @@ +package utilities + +import ( + "github.com/isaacphi/mcp-language-server/internal/logging" +) + +var coreLogger = logging.NewLogger(logging.Core) diff --git a/justfile b/justfile index d4b16bf..340ce08 100644 --- a/justfile +++ b/justfile @@ -23,11 +23,11 @@ check: gofmt -l . test -z "$(gofmt -l .)" go tool staticcheck ./... - go tool govulncheck ./... go tool errcheck ./... find . -path "./integrationtests/workspaces" -prune -o \ -path "./integrationtests/test-output" -prune -o \ -name "*.go" -print | xargs gopls check + go tool govulncheck ./... # Run tests test: