Skip to content

Commit 119c090

Browse files
authored
Merge pull request #1282 from goplus/dev
Release v1.6.1
2 parents 2361774 + c0ed9c5 commit 119c090

File tree

11 files changed

+159
-176
lines changed

11 files changed

+159
-176
lines changed

spx-gui/src/components/editor/code-editor/ui/markdown/CodeView.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,11 @@ const codeHtml = computed(() => {
9999
100100
.addition,
101101
.deletion {
102-
:deep(pre) {
102+
:deep(> pre) {
103103
position: relative;
104104
padding-left: 24px;
105+
// Disable default background and show background from parent (addition/deletion)
106+
background-color: transparent !important;
105107
}
106108
:deep(.line::before) {
107109
position: absolute;

tools/spxls/internal/server/compile.go

Lines changed: 125 additions & 101 deletions
Large diffs are not rendered by default.

tools/spxls/internal/server/definition.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ func (s *Server) textDocumentDefinition(params *DefinitionParams) (any, error) {
3232
if !result.isInFset(objPos) {
3333
return nil, nil
3434
}
35-
return s.createLocationFromPos(result.fset, objPos), nil
35+
return result.locationForPos(objPos), nil
3636
} else if !result.isInFset(defIdent.Pos()) {
3737
return nil, nil
3838
}
39-
return s.createLocationFromIdent(result.fset, defIdent), nil
39+
return result.locationForNode(defIdent), nil
4040
}
4141

4242
// See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#textDocument_typeDefinition
@@ -64,5 +64,5 @@ func (s *Server) textDocumentTypeDefinition(params *TypeDefinitionParams) (any,
6464
if !result.isInFset(objPos) {
6565
return nil, nil
6666
}
67-
return s.createLocationFromPos(result.fset, objPos), nil
67+
return result.locationForPos(objPos), nil
6868
}

tools/spxls/internal/server/document.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,12 @@ func (s *Server) textDocumentDocumentLink(params *DocumentLinkParams) (links []D
2828
// Add links for spx resource references.
2929
links = slices.Grow(links, len(result.spxResourceRefs))
3030
for _, spxResourceRef := range result.spxResourceRefs {
31-
nodePos := result.fset.Position(spxResourceRef.Node.Pos())
32-
if nodePos.Filename != spxFile {
31+
if result.nodeFilename(spxResourceRef.Node) != spxFile {
3332
continue
3433
}
3534
target := URI(spxResourceRef.ID.URI())
3635
links = append(links, DocumentLink{
37-
Range: Range{
38-
Start: FromGopTokenPosition(nodePos),
39-
End: FromGopTokenPosition(result.fset.Position(spxResourceRef.Node.End())),
40-
},
36+
Range: result.rangeForNode(spxResourceRef.Node),
4137
Target: &target,
4238
Data: SpxResourceRefDocumentLinkData{
4339
Kind: spxResourceRef.Kind,
@@ -48,15 +44,11 @@ func (s *Server) textDocumentDocumentLink(params *DocumentLinkParams) (links []D
4844
// Add links for spx definitions.
4945
links = slices.Grow(links, len(result.typeInfo.Defs)+len(result.typeInfo.Uses))
5046
addLinksForIdent := func(ident *gopast.Ident) {
51-
identPos := result.fset.Position(ident.Pos())
52-
if identPos.Filename != spxFile {
47+
if result.nodeFilename(ident) != spxFile {
5348
return
5449
}
5550
if spxDefs := result.spxDefinitionsForIdent(ident); spxDefs != nil {
56-
identRange := Range{
57-
Start: FromGopTokenPosition(identPos),
58-
End: FromGopTokenPosition(result.fset.Position(ident.End())),
59-
}
51+
identRange := result.rangeForNode(ident)
6052
for _, spxDef := range spxDefs {
6153
target := URI(spxDef.ID.String())
6254
links = append(links, DocumentLink{

tools/spxls/internal/server/highlight.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,8 @@ func (s *Server) textDocumentDocumentHighlight(params *DocumentHighlightParams)
144144
}
145145

146146
highlights = append(highlights, DocumentHighlight{
147-
Range: Range{
148-
Start: FromGopTokenPosition(result.fset.Position(ident.Pos())),
149-
End: FromGopTokenPosition(result.fset.Position(ident.End())),
150-
},
151-
Kind: kind,
147+
Range: result.rangeForNode(ident),
148+
Kind: kind,
152149
})
153150
return true
154151
})

tools/spxls/internal/server/hover.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ func (s *Server) textDocumentHover(params *HoverParams) (*Hover, error) {
1818
Kind: Markdown,
1919
Value: spxResourceRef.ID.URI().HTML(),
2020
},
21-
Range: Range{
22-
Start: FromGopTokenPosition(result.fset.Position(spxResourceRef.Node.Pos())),
23-
End: FromGopTokenPosition(result.fset.Position(spxResourceRef.Node.End())),
24-
},
21+
Range: result.rangeForNode(spxResourceRef.Node),
2522
}, nil
2623
}
2724

@@ -44,9 +41,6 @@ func (s *Server) textDocumentHover(params *HoverParams) (*Hover, error) {
4441
Kind: Markdown,
4542
Value: hoverContent.String(),
4643
},
47-
Range: Range{
48-
Start: FromGopTokenPosition(result.fset.Position(ident.Pos())),
49-
End: FromGopTokenPosition(result.fset.Position(ident.End())),
50-
},
44+
Range: result.rangeForNode(ident),
5145
}, nil
5246
}

tools/spxls/internal/server/implementation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (s *Server) textDocumentImplementation(params *ImplementationParams) (any,
2424
}
2525
}
2626

27-
return s.createLocationFromPos(result.fset, obj.Pos()), nil
27+
return result.locationForPos(obj.Pos()), nil
2828
}
2929

3030
// findImplementingMethodDefinitions finds the definition locations of all
@@ -49,7 +49,7 @@ func (s *Server) findImplementingMethodDefinitions(result *compileResult, iface
4949
continue
5050
}
5151

52-
implementations = append(implementations, s.createLocationFromPos(result.fset, method.Pos()))
52+
implementations = append(implementations, result.locationForPos(method.Pos()))
5353
}
5454
}
5555
return implementations

tools/spxls/internal/server/protocol.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ func FromGopTokenPosition(p goptoken.Position) Position {
2626
}
2727
}
2828

29+
// RangeForGopTokenPosition returns a [Range] for the given [goptoken.Position].
30+
func RangeForGopTokenPosition(pos goptoken.Position) Range {
31+
return Range{
32+
Start: FromGopTokenPosition(pos),
33+
End: FromGopTokenPosition(pos),
34+
}
35+
}
36+
2937
// toURI converts a string to a [URI].
3038
func toURI(s string) *URI {
3139
u := URI(s)

tools/spxls/internal/server/reference.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ func (s *Server) textDocumentReferences(params *ReferenceParams) ([]Location, er
3535
if defIdent == nil {
3636
objPos := obj.Pos()
3737
if result.isInFset(objPos) {
38-
locations = append(locations, s.createLocationFromPos(result.fset, objPos))
38+
locations = append(locations, result.locationForPos(objPos))
3939
}
4040
} else if result.isInFset(defIdent.Pos()) {
41-
locations = append(locations, s.createLocationFromIdent(result.fset, defIdent))
41+
locations = append(locations, result.locationForNode(defIdent))
4242
}
4343
}
4444

@@ -53,7 +53,7 @@ func (s *Server) findReferenceLocations(result *compileResult, obj types.Object)
5353
}
5454
locations := make([]Location, 0, len(refIdents))
5555
for _, refIdent := range refIdents {
56-
locations = append(locations, s.createLocationFromIdent(result.fset, refIdent))
56+
locations = append(locations, result.locationForNode(refIdent))
5757
}
5858
return locations
5959
}

tools/spxls/internal/server/rename.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
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

Comments
 (0)