55 "go/types"
66 "slices"
77
8+ "github.com/goplus/builder/tools/spxls/internal/util"
89 gopast "github.com/goplus/gop/ast"
910)
1011
@@ -31,10 +32,7 @@ func (s *Server) textDocumentPrepareRename(params *PrepareRenameParams) (*Range,
3132 return nil , nil
3233 }
3334
34- return & Range {
35- Start : FromGopTokenPosition (result .fset .Position (ident .Pos ())),
36- End : FromGopTokenPosition (result .fset .Position (ident .End ())),
37- }, nil
35+ return util .ToPtr (result .rangeForNode (ident )), nil
3836}
3937
4038// See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#textDocument_rename
@@ -65,16 +63,13 @@ func (s *Server) textDocumentRename(params *RenameParams) (*WorkspaceEdit, error
6563 return nil , fmt .Errorf ("failed to find definition of object %q" , obj .Name ())
6664 }
6765
68- defLoc := s . createLocationFromIdent ( result .fset , defIdent )
66+ defLoc := result .locationForNode ( defIdent )
6967
7068 workspaceEdit := WorkspaceEdit {
7169 Changes : map [DocumentURI ][]TextEdit {
7270 defLoc .URI : {
7371 {
74- Range : Range {
75- Start : FromGopTokenPosition (result .fset .Position (defIdent .Pos ())),
76- End : FromGopTokenPosition (result .fset .Position (defIdent .End ())),
77- },
72+ Range : result .rangeForNode (defIdent ),
7873 NewText : params .NewName ,
7974 },
8075 },
@@ -123,7 +118,7 @@ func (s *Server) spxRenameResourceAtRefs(result *compileResult, id SpxResourceID
123118 nodeEnd .Column --
124119 }
125120
126- documentURI := s . toDocumentURI ( nodePos .Filename )
121+ documentURI := result . documentURIs [ nodePos .Filename ]
127122 textEdit := TextEdit {
128123 Range : Range {
129124 Start : FromGopTokenPosition (nodePos ),
@@ -173,12 +168,9 @@ func (s *Server) spxRenameSpriteResource(result *compileResult, id SpxSpriteReso
173168 continue
174169 }
175170 if tv .Type .String () == "main." + id .SpriteName {
176- documentURI := s . toDocumentURI ( result .fset . Position (expr . Pos ()). Filename )
171+ documentURI := result .nodeDocumentURI (expr )
177172 textEdit := TextEdit {
178- Range : Range {
179- Start : FromGopTokenPosition (result .fset .Position (expr .Pos ())),
180- End : FromGopTokenPosition (result .fset .Position (expr .End ())),
181- },
173+ Range : result .rangeForNode (expr ),
182174 NewText : newName ,
183175 }
184176
0 commit comments