Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): implement file synchronization methods and publish diagnostic notifications #47

Merged
merged 16 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
54ca6af
feat(server): implement file synchronization methods for document not…
go-wyvern Mar 12, 2025
16e16c0
feat(server): enhance LSP notification handlers with detailed comments
go-wyvern Mar 12, 2025
b91d034
chore: update documentation for file synchronization methods
go-wyvern Mar 12, 2025
620e0f7
chore: remove unused imports and clean up code structure
go-wyvern Mar 12, 2025
16521dd
feat(server): implement incremental text document updates and enhance…
go-wyvern Mar 13, 2025
49b673e
test(server): update test case URI for DidChangeTextDocumentParams
go-wyvern Mar 13, 2025
2e2fbf2
fix(server): add mutex for thread-safe diagnostic generation
go-wyvern Mar 13, 2025
b24ab29
feat(project): add ModifyFiles method to handle batch file changes
go-wyvern Mar 13, 2025
c26f3d1
refactor: remove deprecated ModTime field and associated ModifyFiles …
go-wyvern Mar 17, 2025
4738c41
feat(project): implement singleflight to prevent duplicate builder ca…
go-wyvern Mar 17, 2025
22f0c80
refactor(project): remove singleflight usage from cache methods
go-wyvern Mar 17, 2025
2313375
chore(deps): update gogen to v1.16.8 in go.mod and go.sum
go-wyvern Mar 17, 2025
335815b
Merge branch 'main' into text_syncronization
go-wyvern Mar 17, 2025
77c611f
fix(deps): resolve merge conflict in go.sum and update gogen to v1.16.8
go-wyvern Mar 17, 2025
4905ee1
chore(deps): update gop package from v1.3.5 to v1.3.6
go-wyvern Mar 17, 2025
b51fa4d
refactor(server): replace PositionOffset method with positionOffset f…
go-wyvern Mar 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/goplus/goxlsw
go 1.23.4

require (
github.com/goplus/gogen v1.16.7
github.com/goplus/gogen v1.16.8
github.com/goplus/gop v1.3.6
github.com/goplus/mod v0.13.17
github.com/goplus/spx v1.1.1-0.20250214074125-e9e1f6362499
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF0
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/goplus/canvas v0.1.0 h1:Vx3f2+U8UANvWf5/01YsQYKNbZDm1GZCjhlEBFrQkeU=
github.com/goplus/canvas v0.1.0/go.mod h1:Rhcvo5qkpD9WuXFnvnXtrBSY97l6h7sXQuofrmiLNdM=
github.com/goplus/gogen v1.16.7 h1:OVN6byjWVtzs4plS7q80h747Jh8G7J+VUPN0L9YWQ68=
github.com/goplus/gogen v1.16.7/go.mod h1:6TQYbabXDF9LCdDkOOzHmfg1R4ENfXQ3XpHa9RhTSD8=
github.com/goplus/gogen v1.16.8 h1:idakC+4OZIAvDSi3wkPGHlhpNEd7xkmvodXDMDvfn4s=
github.com/goplus/gogen v1.16.8/go.mod h1:6TQYbabXDF9LCdDkOOzHmfg1R4ENfXQ3XpHa9RhTSD8=
github.com/goplus/gop v1.3.6 h1:I9GUJXt+elFXjO3tNi/BXWiR7MujHoxrdawLQfMPrTM=
github.com/goplus/gop v1.3.6/go.mod h1:grsLKBbSesOXhwXH9tktcXHi+SBOn/yk4LKsL3dRmMg=
github.com/goplus/mod v0.13.17 h1:aWp14xosENrh7t0/0qcIejDmQEiTgI3ou2+KoLDlSlE=
Expand Down
4 changes: 4 additions & 0 deletions gop/proj.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ type fileKey struct {
type File = *FileImpl
type FileImpl struct {
Content []byte
// Deprecated: ModTime is no longer supported due to lsp text sync specification. Use Version instead.
ModTime time.Time
Version int
}

// Project represents a project.
Expand Down Expand Up @@ -276,6 +278,7 @@ func (p *Project) FileCache(kind, path string) (any, error) {
if !ok {
return nil, fs.ErrNotExist
}

data, err := builder(p, path, file)
p.fileCaches.Store(key, encodeDataOrErr(data, err))
return data, err
Expand All @@ -290,6 +293,7 @@ func (p *Project) Cache(kind string) (any, error) {
if !ok {
return nil, ErrUnknownKind
}

data, err := builder(p)
p.caches.Store(kind, encodeDataOrErr(data, err))
return data, err
Expand Down
48 changes: 44 additions & 4 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"slices"
"strings"

gopast "github.com/goplus/gop/ast"
goptoken "github.com/goplus/gop/token"
"github.com/goplus/goxlsw/gop"
"github.com/goplus/goxlsw/internal/analysis"
"github.com/goplus/goxlsw/internal/vfs"
Expand Down Expand Up @@ -242,25 +244,26 @@
if err := UnmarshalJSON(n.Params(), &params); err != nil {
return fmt.Errorf("failed to parse didOpen params: %w", err)
}
return errors.New("TODO")

return s.didOpen(&params)

Check warning on line 248 in internal/server/server.go

View check run for this annotation

Codecov / codecov/patch

internal/server/server.go#L248

Added line #L248 was not covered by tests
case "textDocument/didChange":
var params DidChangeTextDocumentParams
if err := UnmarshalJSON(n.Params(), &params); err != nil {
return fmt.Errorf("failed to parse didChange params: %w", err)
}
return errors.New("TODO")
return s.didChange(&params)

Check warning on line 254 in internal/server/server.go

View check run for this annotation

Codecov / codecov/patch

internal/server/server.go#L254

Added line #L254 was not covered by tests
case "textDocument/didSave":
var params DidSaveTextDocumentParams
if err := UnmarshalJSON(n.Params(), &params); err != nil {
return fmt.Errorf("failed to parse didSave params: %w", err)
}
return errors.New("TODO")
return s.didSave(&params)

Check warning on line 260 in internal/server/server.go

View check run for this annotation

Codecov / codecov/patch

internal/server/server.go#L260

Added line #L260 was not covered by tests
case "textDocument/didClose":
var params DidCloseTextDocumentParams
if err := UnmarshalJSON(n.Params(), &params); err != nil {
return fmt.Errorf("failed to parse didClose params: %w", err)
}
return errors.New("TODO")
return s.didClose(&params)

Check warning on line 266 in internal/server/server.go

View check run for this annotation

Codecov / codecov/patch

internal/server/server.go#L266

Added line #L266 was not covered by tests
}
return nil
}
Expand Down Expand Up @@ -333,3 +336,40 @@
func (s *Server) toDocumentURI(path string) DocumentURI {
return DocumentURI(string(s.workspaceRootURI) + path)
}

// fromPosition converts a token.Position to an LSP Position.
func (s *Server) fromPosition(astFile *gopast.File, position goptoken.Position) Position {
tokenFile := s.getProj().Fset.File(astFile.Pos())

line := position.Line
lineStart := int(tokenFile.LineStart(line))
relLineStart := lineStart - tokenFile.Base()
lineContent := astFile.Code[relLineStart : relLineStart+position.Column-1]
utf16Offset := utf8OffsetToUTF16(string(lineContent), position.Column-1)

return Position{
Line: uint32(position.Line - 1),
Character: uint32(utf16Offset),
}
}

// rangeForASTFilePosition returns a [Range] for the given position in an AST file.
func (s *Server) rangeForASTFilePosition(astFile *gopast.File, position goptoken.Position) Range {
p := s.fromPosition(astFile, position)
return Range{Start: p, End: p}
}

// rangeForPos returns the [Range] for the given position.
func (s *Server) rangeForPos(pos goptoken.Pos) Range {
return s.rangeForASTFilePosition(s.posASTFile(pos), s.getProj().Fset.Position(pos))
}

// posASTFile returns the AST file for the given position.
func (s *Server) posASTFile(pos goptoken.Pos) *gopast.File {
return getASTPkg(s.getProj()).Files[s.posFilename(pos)]
}

// posFilename returns the filename for the given position.
func (s *Server) posFilename(pos goptoken.Pos) string {
return s.getProj().Fset.Position(pos).Filename
}
Loading