Skip to content

Commit 24b38de

Browse files
authored
Move change tracker, converters, utils to separate packages (#1977)
1 parent b278afd commit 24b38de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+637
-564
lines changed

internal/ast/symbol.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ type Symbol struct {
2323
GlobalExports SymbolTable // Conditional global UMD exports
2424
}
2525

26+
func (s *Symbol) IsExternalModule() bool {
27+
return s.Flags&SymbolFlagsModule != 0 && len(s.Name) > 0 && s.Name[0] == '"'
28+
}
29+
30+
func (s *Symbol) IsStatic() bool {
31+
if s.ValueDeclaration == nil {
32+
return false
33+
}
34+
modifierFlags := s.ValueDeclaration.ModifierFlags()
35+
return modifierFlags&ModifierFlagsStatic != 0
36+
}
37+
2638
// SymbolTable
2739

2840
type SymbolTable map[string]*Symbol

internal/ast/utilities.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3526,6 +3526,10 @@ func IsTypeDeclarationName(name *Node) bool {
35263526
GetNameOfDeclaration(name.Parent) == name
35273527
}
35283528

3529+
func IsRightSideOfPropertyAccess(node *Node) bool {
3530+
return node.Parent.Kind == KindPropertyAccessExpression && node.Parent.Name() == node
3531+
}
3532+
35293533
func IsRightSideOfQualifiedNameOrPropertyAccess(node *Node) bool {
35303534
parent := node.Parent
35313535
switch parent.Kind {

internal/core/core.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,3 +687,13 @@ func DeduplicateSorted[T any](slice []T, isEqual func(a, b T) bool) []T {
687687

688688
return deduplicated
689689
}
690+
691+
// CompareBooleans treats true as greater than false.
692+
func CompareBooleans(a, b bool) int {
693+
if a && !b {
694+
return -1
695+
} else if !a && b {
696+
return 1
697+
}
698+
return 0
699+
}

internal/format/rulecontext.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/microsoft/typescript-go/internal/ast"
77
"github.com/microsoft/typescript-go/internal/astnav"
88
"github.com/microsoft/typescript-go/internal/core"
9-
"github.com/microsoft/typescript-go/internal/lsutil"
9+
"github.com/microsoft/typescript-go/internal/ls/lsutil"
1010
"github.com/microsoft/typescript-go/internal/scanner"
1111
)
1212

internal/fourslash/_scripts/convertFourslash.mts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ function parseUserPreferences(arg: ts.ObjectLiteralExpression): string | undefin
12051205
preferences.push(`UseAliasesForRename: ${stringToTristate(prop.initializer.getText())}`);
12061206
break;
12071207
case "quotePreference":
1208-
preferences.push(`QuotePreference: ls.QuotePreference(${prop.initializer.getText()})`);
1208+
preferences.push(`QuotePreference: lsutil.QuotePreference(${prop.initializer.getText()})`);
12091209
break;
12101210
}
12111211
}
@@ -1216,7 +1216,7 @@ function parseUserPreferences(arg: ts.ObjectLiteralExpression): string | undefin
12161216
if (preferences.length === 0) {
12171217
return "nil /*preferences*/";
12181218
}
1219-
return `&ls.UserPreferences{${preferences.join(",")}}`;
1219+
return `&lsutil.UserPreferences{${preferences.join(",")}}`;
12201220
}
12211221

12221222
function parseBaselineMarkerOrRangeArg(arg: ts.Expression): string | undefined {
@@ -1813,6 +1813,9 @@ function generateGoTest(failingTests: Set<string>, test: GoTest): string {
18131813
if (commands.includes("ls.")) {
18141814
imports.push(`"github.com/microsoft/typescript-go/internal/ls"`);
18151815
}
1816+
if (commands.includes("lsutil.")) {
1817+
imports.push(`"github.com/microsoft/typescript-go/internal/ls/lsutil"`);
1818+
}
18161819
if (commands.includes("lsproto.")) {
18171820
imports.push(`"github.com/microsoft/typescript-go/internal/lsp/lsproto"`);
18181821
}

internal/fourslash/baselineutil.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/microsoft/typescript-go/internal/collections"
1414
"github.com/microsoft/typescript-go/internal/core"
1515
"github.com/microsoft/typescript-go/internal/debug"
16-
"github.com/microsoft/typescript-go/internal/ls"
16+
"github.com/microsoft/typescript-go/internal/ls/lsconv"
1717
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
1818
"github.com/microsoft/typescript-go/internal/stringutil"
1919
"github.com/microsoft/typescript-go/internal/testutil/baseline"
@@ -163,7 +163,7 @@ func (f *FourslashTest) getBaselineForGroupedLocationsWithFileContents(groupedRa
163163
return nil
164164
}
165165

166-
fileName := ls.FileNameToDocumentURI(path)
166+
fileName := lsconv.FileNameToDocumentURI(path)
167167
ranges := groupedRanges.Get(fileName)
168168
if len(ranges) == 0 {
169169
return nil
@@ -219,7 +219,7 @@ func (f *FourslashTest) getBaselineContentForFile(
219219
detailPrefixes := map[*baselineDetail]string{}
220220
detailSuffixes := map[*baselineDetail]string{}
221221
canDetermineContextIdInline := true
222-
uri := ls.FileNameToDocumentURI(fileName)
222+
uri := lsconv.FileNameToDocumentURI(fileName)
223223

224224
if options.marker != nil && options.marker.FileName() == fileName {
225225
details = append(details, &baselineDetail{pos: options.marker.LSPos(), positionMarker: options.markerName})
@@ -258,7 +258,7 @@ func (f *FourslashTest) getBaselineContentForFile(
258258
}
259259

260260
slices.SortStableFunc(details, func(d1, d2 *baselineDetail) int {
261-
return ls.ComparePositions(d1.pos, d2.pos)
261+
return lsproto.ComparePositions(d1.pos, d2.pos)
262262
})
263263
// !!! if canDetermineContextIdInline
264264

@@ -362,20 +362,20 @@ type textWithContext struct {
362362
isLibFile bool
363363
fileName string
364364
content string // content of the original file
365-
lineStarts *ls.LSPLineMap
366-
converters *ls.Converters
365+
lineStarts *lsconv.LSPLineMap
366+
converters *lsconv.Converters
367367

368368
// posLineInfo
369369
posInfo *lsproto.Position
370370
lineInfo int
371371
}
372372

373-
// implements ls.Script
373+
// implements lsconv.Script
374374
func (t *textWithContext) FileName() string {
375375
return t.fileName
376376
}
377377

378-
// implements ls.Script
378+
// implements lsconv.Script
379379
func (t *textWithContext) Text() string {
380380
return t.content
381381
}
@@ -391,10 +391,10 @@ func newTextWithContext(fileName string, content string) *textWithContext {
391391
pos: lsproto.Position{Line: 0, Character: 0},
392392
fileName: fileName,
393393
content: content,
394-
lineStarts: ls.ComputeLSPLineStarts(content),
394+
lineStarts: lsconv.ComputeLSPLineStarts(content),
395395
}
396396

397-
t.converters = ls.NewConverters(lsproto.PositionEncodingKindUTF8, func(_ string) *ls.LSPLineMap {
397+
t.converters = lsconv.NewConverters(lsproto.PositionEncodingKindUTF8, func(_ string) *lsconv.LSPLineMap {
398398
return t.lineStarts
399399
})
400400
t.readableContents.WriteString("// === " + fileName + " ===")

0 commit comments

Comments
 (0)