mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-15 22:15:07 +00:00
Fix gopls replace_symbol_body corrupting type/var/const declarations
gopls reports the document-symbol range of single type/var/const declarations starting at the identifier (after the keyword), unlike func declarations whose range includes the func keyword. Serena derives both the displayed body and the replacement range from that range, so the keyword was dropped from both for these declarations and a keyword-inclusive edit corrupted the file (type Foo became type type Foo). Override request_document_symbols in gopls to extend the range start back to the keyword when only the keyword and indentation precede the identifier, recomputing the body so it stays consistent with the replacement range. Funcs, grouped declarations, and selectionRange are left untouched. Adds a unit test for the symbol body and range plus an end-to-end replace_symbol_body round-trip regression test.
This commit is contained in:
1 parent
18d4cc007b
commit
61cf7c7d38
6 files changed
+254
-1
No files matched your search
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
// BodyStruct is a single type declaration used to verify that replace_symbol_body
|
||||
// includes the leading `type` keyword in the symbol body and replacement range.
|
||||
type BodyStruct struct {
|
||||
Value int
|
||||
}
|
||||
|
||||
// NamedInt is a single defined-type declaration (non-struct).
|
||||
type NamedInt int
|
||||
|
||||
// AliasInt is a type alias declaration.
|
||||
type AliasInt = int
|
||||
|
||||
// GlobalCounter is a single package-level var declaration.
|
||||
var GlobalCounter int = 0
|
||||
|
||||
// MaxItems is a single package-level const declaration.
|
||||
const MaxItems = 100
|
||||
|
||||
// GroupedA and GroupedB are declared in a grouped var block, where the `var`
|
||||
// keyword is on a separate line and must NOT be folded into either symbol body.
|
||||
var (
|
||||
GroupedA int = 1
|
||||
GroupedB string = "two"
|
||||
)
|
||||
Reference in new issue
Block a user