Skip to content

Commit ca93817

Browse files
committed
refactor
1 parent 8423ecf commit ca93817

File tree

2 files changed

+9
-36
lines changed

2 files changed

+9
-36
lines changed

internal/ls/definition.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,28 +57,6 @@ func (l *LanguageService) ProvideDefinition(ctx context.Context, documentURI lsp
5757
return l.createLocationsFromDeclarations(declarations), nil
5858
}
5959

60-
// func (l *LanguageService) getMappedDefinition(definitions lsproto.DefinitionResponse) lsproto.DefinitionResponse {
61-
// if definitions.Location != nil {
62-
// definitions.Location = l.getMappedLocation(definitions.Location)
63-
// }
64-
// if definitions.Locations != nil {
65-
// for i, loc := range *definitions.Locations {
66-
// (*definitions.Locations)[i] = *l.getMappedLocation(&loc)
67-
// }
68-
// }
69-
// if definitions.DefinitionLinks != nil {
70-
// for i, link := range *definitions.DefinitionLinks {
71-
// mappedTarget := l.getMappedLocation(&lsproto.Location{Uri: link.TargetUri, Range: link.TargetRange})
72-
// mappedSelection := l.getMappedLocation(&lsproto.Location{Uri: link.TargetUri, Range: link.TargetSelectionRange})
73-
// debug.Assert(mappedTarget.Uri == mappedSelection.Uri, "target and selection should be in same file")
74-
// (*definitions.DefinitionLinks)[i].TargetUri = mappedTarget.Uri
75-
// (*definitions.DefinitionLinks)[i].TargetRange = mappedTarget.Range
76-
// (*definitions.DefinitionLinks)[i].TargetSelectionRange = mappedSelection.Range
77-
// }
78-
// }
79-
// return definitions
80-
// }
81-
8260
func (l *LanguageService) ProvideTypeDefinition(ctx context.Context, documentURI lsproto.DocumentUri, position lsproto.Position) (lsproto.DefinitionResponse, error) {
8361
program, file := l.getProgramAndFile(documentURI)
8462
node := astnav.GetTouchingPropertyName(file, int(l.converters.LineAndCharacterToPosition(file, position)))

internal/project/snapshotfs.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@ type snapshotFS struct {
2727
fs vfs.FS
2828
overlays map[tspath.Path]*overlay
2929
diskFiles map[tspath.Path]*diskFile
30-
readFiles collections.SyncMap[tspath.Path, memoizedFileEntry]
30+
readFiles collections.SyncMap[tspath.Path, memoizedDiskFile]
3131
}
3232

33-
// !!! newtype?
34-
type memoizedFileEntry struct {
35-
read func() *diskFile
36-
}
33+
type memoizedDiskFile func() *diskFile
3734

3835
func (s *snapshotFS) FS() vfs.FS {
3936
return s.fs
@@ -46,16 +43,14 @@ func (s *snapshotFS) GetFile(fileName string) FileHandle {
4643
if file, ok := s.diskFiles[s.toPath(fileName)]; ok {
4744
return file
4845
}
49-
newEntry := memoizedFileEntry{
50-
read: sync.OnceValue(func() *diskFile {
51-
if contents, ok := s.fs.ReadFile(fileName); ok {
52-
return newDiskFile(fileName, contents)
53-
}
54-
return nil
55-
}),
56-
}
46+
newEntry := memoizedDiskFile(sync.OnceValue(func() *diskFile {
47+
if contents, ok := s.fs.ReadFile(fileName); ok {
48+
return newDiskFile(fileName, contents)
49+
}
50+
return nil
51+
}))
5752
if entry, ok := s.readFiles.LoadOrStore(s.toPath(fileName), newEntry); ok {
58-
return entry.read()
53+
return entry()
5954
}
6055
return nil
6156
}

0 commit comments

Comments
 (0)