Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions internal/ast/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ type Symbol struct {
GlobalExports SymbolTable // Conditional global UMD exports
}

func (s *Symbol) IsExternalModule() bool {
return s.Flags&SymbolFlagsModule != 0 && len(s.Name) > 0 && s.Name[0] == '"'
}

func (s *Symbol) IsStatic() bool {
if s.ValueDeclaration == nil {
return false
}
modifierFlags := s.ValueDeclaration.ModifierFlags()
return modifierFlags&ModifierFlagsStatic != 0
}

// SymbolTable

type SymbolTable map[string]*Symbol
Expand Down
4 changes: 4 additions & 0 deletions internal/ast/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -3526,6 +3526,10 @@ func IsTypeDeclarationName(name *Node) bool {
GetNameOfDeclaration(name.Parent) == name
}

func IsRightSideOfPropertyAccess(node *Node) bool {
return node.Parent.Kind == KindPropertyAccessExpression && node.Parent.Name() == node
}

func IsRightSideOfQualifiedNameOrPropertyAccess(node *Node) bool {
parent := node.Parent
switch parent.Kind {
Expand Down
10 changes: 10 additions & 0 deletions internal/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,3 +687,13 @@ func DeduplicateSorted[T any](slice []T, isEqual func(a, b T) bool) []T {

return deduplicated
}

// CompareBooleans treats true as greater than false.
func CompareBooleans(a, b bool) int {
if a && !b {
return -1
} else if !a && b {
return 1
}
return 0
}
2 changes: 1 addition & 1 deletion internal/format/rulecontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/microsoft/typescript-go/internal/ast"
"github.com/microsoft/typescript-go/internal/astnav"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/lsutil"
"github.com/microsoft/typescript-go/internal/ls/lsutil"
"github.com/microsoft/typescript-go/internal/scanner"
)

Expand Down
7 changes: 5 additions & 2 deletions internal/fourslash/_scripts/convertFourslash.mts
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ function parseUserPreferences(arg: ts.ObjectLiteralExpression): string | undefin
preferences.push(`UseAliasesForRename: ${stringToTristate(prop.initializer.getText())}`);
break;
case "quotePreference":
preferences.push(`QuotePreference: ls.QuotePreference(${prop.initializer.getText()})`);
preferences.push(`QuotePreference: lsutil.QuotePreference(${prop.initializer.getText()})`);
break;
}
}
Expand All @@ -1216,7 +1216,7 @@ function parseUserPreferences(arg: ts.ObjectLiteralExpression): string | undefin
if (preferences.length === 0) {
return "nil /*preferences*/";
}
return `&ls.UserPreferences{${preferences.join(",")}}`;
return `&lsutil.UserPreferences{${preferences.join(",")}}`;
}

function parseBaselineMarkerOrRangeArg(arg: ts.Expression): string | undefined {
Expand Down Expand Up @@ -1813,6 +1813,9 @@ function generateGoTest(failingTests: Set<string>, test: GoTest): string {
if (commands.includes("ls.")) {
imports.push(`"github.com/microsoft/typescript-go/internal/ls"`);
}
if (commands.includes("lsutil.")) {
imports.push(`"github.com/microsoft/typescript-go/internal/ls/lsutil"`);
}
if (commands.includes("lsproto.")) {
imports.push(`"github.com/microsoft/typescript-go/internal/lsp/lsproto"`);
}
Expand Down
20 changes: 10 additions & 10 deletions internal/fourslash/baselineutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/microsoft/typescript-go/internal/collections"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/debug"
"github.com/microsoft/typescript-go/internal/ls"
"github.com/microsoft/typescript-go/internal/ls/lsconv"
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
"github.com/microsoft/typescript-go/internal/stringutil"
"github.com/microsoft/typescript-go/internal/testutil/baseline"
Expand Down Expand Up @@ -163,7 +163,7 @@ func (f *FourslashTest) getBaselineForGroupedLocationsWithFileContents(groupedRa
return nil
}

fileName := ls.FileNameToDocumentURI(path)
fileName := lsconv.FileNameToDocumentURI(path)
ranges := groupedRanges.Get(fileName)
if len(ranges) == 0 {
return nil
Expand Down Expand Up @@ -219,7 +219,7 @@ func (f *FourslashTest) getBaselineContentForFile(
detailPrefixes := map[*baselineDetail]string{}
detailSuffixes := map[*baselineDetail]string{}
canDetermineContextIdInline := true
uri := ls.FileNameToDocumentURI(fileName)
uri := lsconv.FileNameToDocumentURI(fileName)

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

slices.SortStableFunc(details, func(d1, d2 *baselineDetail) int {
return ls.ComparePositions(d1.pos, d2.pos)
return lsproto.ComparePositions(d1.pos, d2.pos)
})
// !!! if canDetermineContextIdInline

Expand Down Expand Up @@ -362,20 +362,20 @@ type textWithContext struct {
isLibFile bool
fileName string
content string // content of the original file
lineStarts *ls.LSPLineMap
converters *ls.Converters
lineStarts *lsconv.LSPLineMap
converters *lsconv.Converters

// posLineInfo
posInfo *lsproto.Position
lineInfo int
}

// implements ls.Script
// implements lsconv.Script
func (t *textWithContext) FileName() string {
return t.fileName
}

// implements ls.Script
// implements lsconv.Script
func (t *textWithContext) Text() string {
return t.content
}
Expand All @@ -391,10 +391,10 @@ func newTextWithContext(fileName string, content string) *textWithContext {
pos: lsproto.Position{Line: 0, Character: 0},
fileName: fileName,
content: content,
lineStarts: ls.ComputeLSPLineStarts(content),
lineStarts: lsconv.ComputeLSPLineStarts(content),
}

t.converters = ls.NewConverters(lsproto.PositionEncodingKindUTF8, func(_ string) *ls.LSPLineMap {
t.converters = lsconv.NewConverters(lsproto.PositionEncodingKindUTF8, func(_ string) *lsconv.LSPLineMap {
return t.lineStarts
})
t.readableContents.WriteString("// === " + fileName + " ===")
Expand Down
Loading