Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
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
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
49 changes: 25 additions & 24 deletions internal/fourslash/fourslash.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/microsoft/typescript-go/internal/collections"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/ls"
"github.com/microsoft/typescript-go/internal/ls/lsconv"
"github.com/microsoft/typescript-go/internal/lsp"
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
"github.com/microsoft/typescript-go/internal/project"
Expand All @@ -41,7 +42,7 @@ type FourslashTest struct {
rangesByText *collections.MultiMap[string, *RangeMarker]

scriptInfos map[string]*scriptInfo
converters *ls.Converters
converters *lsconv.Converters

userPreferences *ls.UserPreferences
currentCaretPosition lsproto.Position
Expand All @@ -53,22 +54,22 @@ type FourslashTest struct {
type scriptInfo struct {
fileName string
content string
lineMap *ls.LSPLineMap
lineMap *lsconv.LSPLineMap
version int32
}

func newScriptInfo(fileName string, content string) *scriptInfo {
return &scriptInfo{
fileName: fileName,
content: content,
lineMap: ls.ComputeLSPLineStarts(content),
lineMap: lsconv.ComputeLSPLineStarts(content),
version: 1,
}
}

func (s *scriptInfo) editContent(start int, end int, newText string) {
s.content = s.content[:start] + newText + s.content[end:]
s.lineMap = ls.ComputeLSPLineStarts(s.content)
s.lineMap = lsconv.ComputeLSPLineStarts(s.content)
s.version++
}

Expand Down Expand Up @@ -172,7 +173,7 @@ func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, conten
}
}()

converters := ls.NewConverters(lsproto.PositionEncodingKindUTF8, func(fileName string) *ls.LSPLineMap {
converters := lsconv.NewConverters(lsproto.PositionEncodingKindUTF8, func(fileName string) *lsconv.LSPLineMap {
scriptInfo, ok := scriptInfos[fileName]
if !ok {
return nil
Expand Down Expand Up @@ -486,7 +487,7 @@ func (f *FourslashTest) openFile(t *testing.T, filename string) {
f.activeFilename = filename
sendNotification(t, f, lsproto.TextDocumentDidOpenInfo, &lsproto.DidOpenTextDocumentParams{
TextDocument: &lsproto.TextDocumentItem{
Uri: ls.FileNameToDocumentURI(filename),
Uri: lsconv.FileNameToDocumentURI(filename),
LanguageId: getLanguageKind(filename),
Text: script.content,
},
Expand Down Expand Up @@ -627,7 +628,7 @@ func (f *FourslashTest) getCompletions(t *testing.T, userPreferences *ls.UserPre
prefix := f.getCurrentPositionPrefix()
params := &lsproto.CompletionParams{
TextDocument: lsproto.TextDocumentIdentifier{
Uri: ls.FileNameToDocumentURI(f.activeFilename),
Uri: lsconv.FileNameToDocumentURI(f.activeFilename),
},
Position: f.currentCaretPosition,
Context: &lsproto.CompletionContext{},
Expand Down Expand Up @@ -988,7 +989,7 @@ func (f *FourslashTest) VerifyBaselineFindAllReferences(

params := &lsproto.ReferenceParams{
TextDocument: lsproto.TextDocumentIdentifier{
Uri: ls.FileNameToDocumentURI(f.activeFilename),
Uri: lsconv.FileNameToDocumentURI(f.activeFilename),
},
Position: f.currentCaretPosition,
Context: &lsproto.ReferenceContext{},
Expand Down Expand Up @@ -1029,7 +1030,7 @@ func (f *FourslashTest) VerifyBaselineGoToDefinition(

params := &lsproto.DefinitionParams{
TextDocument: lsproto.TextDocumentIdentifier{
Uri: ls.FileNameToDocumentURI(f.activeFilename),
Uri: lsconv.FileNameToDocumentURI(f.activeFilename),
},
Position: f.currentCaretPosition,
}
Expand Down Expand Up @@ -1078,7 +1079,7 @@ func (f *FourslashTest) VerifyBaselineGoToTypeDefinition(

params := &lsproto.TypeDefinitionParams{
TextDocument: lsproto.TextDocumentIdentifier{
Uri: ls.FileNameToDocumentURI(f.activeFilename),
Uri: lsconv.FileNameToDocumentURI(f.activeFilename),
},
Position: f.currentCaretPosition,
}
Expand Down Expand Up @@ -1123,7 +1124,7 @@ func (f *FourslashTest) VerifyBaselineHover(t *testing.T) {

params := &lsproto.HoverParams{
TextDocument: lsproto.TextDocumentIdentifier{
Uri: ls.FileNameToDocumentURI(f.activeFilename),
Uri: lsconv.FileNameToDocumentURI(f.activeFilename),
},
Position: marker.LSPosition,
}
Expand Down Expand Up @@ -1194,7 +1195,7 @@ func (f *FourslashTest) VerifyBaselineSignatureHelp(t *testing.T) {

params := &lsproto.SignatureHelpParams{
TextDocument: lsproto.TextDocumentIdentifier{
Uri: ls.FileNameToDocumentURI(f.activeFilename),
Uri: lsconv.FileNameToDocumentURI(f.activeFilename),
},
Position: marker.LSPosition,
}
Expand Down Expand Up @@ -1315,7 +1316,7 @@ func (f *FourslashTest) VerifyBaselineSelectionRanges(t *testing.T) {
// Get selection ranges at this marker
params := &lsproto.SelectionRangeParams{
TextDocument: lsproto.TextDocumentIdentifier{
Uri: ls.FileNameToDocumentURI(marker.FileName()),
Uri: lsconv.FileNameToDocumentURI(marker.FileName()),
},
Positions: []lsproto.Position{marker.LSPosition},
}
Expand Down Expand Up @@ -1473,7 +1474,7 @@ func (f *FourslashTest) verifyBaselineDocumentHighlights(

params := &lsproto.DocumentHighlightParams{
TextDocument: lsproto.TextDocumentIdentifier{
Uri: ls.FileNameToDocumentURI(f.activeFilename),
Uri: lsconv.FileNameToDocumentURI(f.activeFilename),
},
Position: f.currentCaretPosition,
}
Expand Down Expand Up @@ -1501,7 +1502,7 @@ func (f *FourslashTest) verifyBaselineDocumentHighlights(
var spans []lsproto.Location
for _, h := range *highlights {
spans = append(spans, lsproto.Location{
Uri: ls.FileNameToDocumentURI(f.activeFilename),
Uri: lsconv.FileNameToDocumentURI(f.activeFilename),
Range: h.Range,
})
}
Expand Down Expand Up @@ -1700,7 +1701,7 @@ func (f *FourslashTest) editScript(t *testing.T, fileName string, start int, end
}
sendNotification(t, f, lsproto.TextDocumentDidChangeInfo, &lsproto.DidChangeTextDocumentParams{
TextDocument: lsproto.VersionedTextDocumentIdentifier{
Uri: ls.FileNameToDocumentURI(fileName),
Uri: lsconv.FileNameToDocumentURI(fileName),
Version: script.version,
},
ContentChanges: []lsproto.TextDocumentContentChangePartialOrWholeDocument{
Expand Down Expand Up @@ -1729,7 +1730,7 @@ func (f *FourslashTest) VerifyQuickInfoAt(t *testing.T, marker string, expectedT
func (f *FourslashTest) getQuickInfoAtCurrentPosition(t *testing.T) *lsproto.Hover {
params := &lsproto.HoverParams{
TextDocument: lsproto.TextDocumentIdentifier{
Uri: ls.FileNameToDocumentURI(f.activeFilename),
Uri: lsconv.FileNameToDocumentURI(f.activeFilename),
},
Position: f.currentCaretPosition,
}
Expand Down Expand Up @@ -1839,7 +1840,7 @@ func (f *FourslashTest) verifySignatureHelp(
prefix := f.getCurrentPositionPrefix()
params := &lsproto.SignatureHelpParams{
TextDocument: lsproto.TextDocumentIdentifier{
Uri: ls.FileNameToDocumentURI(f.activeFilename),
Uri: lsconv.FileNameToDocumentURI(f.activeFilename),
},
Position: f.currentCaretPosition,
Context: context,
Expand Down Expand Up @@ -1881,7 +1882,7 @@ func (f *FourslashTest) BaselineAutoImportsCompletions(t *testing.T, markerNames
f.GoToMarker(t, markerName)
params := &lsproto.CompletionParams{
TextDocument: lsproto.TextDocumentIdentifier{
Uri: ls.FileNameToDocumentURI(f.activeFilename),
Uri: lsconv.FileNameToDocumentURI(f.activeFilename),
},
Position: f.currentCaretPosition,
Context: &lsproto.CompletionContext{},
Expand Down Expand Up @@ -1912,7 +1913,7 @@ func (f *FourslashTest) BaselineAutoImportsCompletions(t *testing.T, markerNames
)))

currentFile := newScriptInfo(f.activeFilename, fileContent)
converters := ls.NewConverters(lsproto.PositionEncodingKindUTF8, func(_ string) *ls.LSPLineMap {
converters := lsconv.NewConverters(lsproto.PositionEncodingKindUTF8, func(_ string) *lsconv.LSPLineMap {
return currentFile.lineMap
})
var list []*lsproto.CompletionItem
Expand Down Expand Up @@ -1959,7 +1960,7 @@ func (f *FourslashTest) BaselineAutoImportsCompletions(t *testing.T, markerNames
// }
// allChanges := append(allChanges, completionChange)
// sorted from back-of-file-most to front-of-file-most
slices.SortFunc(allChanges, func(a, b *lsproto.TextEdit) int { return ls.ComparePositions(b.Range.Start, a.Range.Start) })
slices.SortFunc(allChanges, func(a, b *lsproto.TextEdit) int { return lsproto.ComparePositions(b.Range.Start, a.Range.Start) })
newFileContent := fileContent
for _, change := range allChanges {
newFileContent = newFileContent[:converters.LineAndCharacterToPosition(currentFile, change.Range.Start)] + change.NewText + newFileContent[converters.LineAndCharacterToPosition(currentFile, change.Range.End):]
Expand Down Expand Up @@ -2009,7 +2010,7 @@ func (f *FourslashTest) verifyBaselineRename(
// !!! set preferences
params := &lsproto.RenameParams{
TextDocument: lsproto.TextDocumentIdentifier{
Uri: ls.FileNameToDocumentURI(f.activeFilename),
Uri: lsconv.FileNameToDocumentURI(f.activeFilename),
},
Position: f.currentCaretPosition,
NewName: "?",
Expand Down Expand Up @@ -2090,7 +2091,7 @@ func (f *FourslashTest) VerifyRenameSucceeded(t *testing.T, preferences *ls.User
// !!! set preferences
params := &lsproto.RenameParams{
TextDocument: lsproto.TextDocumentIdentifier{
Uri: ls.FileNameToDocumentURI(f.activeFilename),
Uri: lsconv.FileNameToDocumentURI(f.activeFilename),
},
Position: f.currentCaretPosition,
NewName: "?",
Expand All @@ -2114,7 +2115,7 @@ func (f *FourslashTest) VerifyRenameFailed(t *testing.T, preferences *ls.UserPre
// !!! set preferences
params := &lsproto.RenameParams{
TextDocument: lsproto.TextDocumentIdentifier{
Uri: ls.FileNameToDocumentURI(f.activeFilename),
Uri: lsconv.FileNameToDocumentURI(f.activeFilename),
},
Position: f.currentCaretPosition,
NewName: "?",
Expand Down
12 changes: 6 additions & 6 deletions internal/fourslash/test_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/go-json-experiment/json"
"github.com/microsoft/typescript-go/internal/core"
"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/testrunner"
Expand Down Expand Up @@ -163,17 +163,17 @@ type TestFileInfo struct {
emit bool
}

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

// Text implements ls.Script.
// Text implements lsconv.Script.
func (t *TestFileInfo) Text() string {
return t.Content
}

var _ ls.Script = (*TestFileInfo)(nil)
var _ lsconv.Script = (*TestFileInfo)(nil)

const emitThisFileOption = "emitthisfile"

Expand Down Expand Up @@ -368,8 +368,8 @@ func parseFileContent(fileName string, content string, fileOptions map[string]st

outputString := output.String()
// Set LS positions for markers
lineMap := ls.ComputeLSPLineStarts(outputString)
converters := ls.NewConverters(lsproto.PositionEncodingKindUTF8, func(_ string) *ls.LSPLineMap {
lineMap := lsconv.ComputeLSPLineStarts(outputString)
converters := lsconv.NewConverters(lsproto.PositionEncodingKindUTF8, func(_ string) *lsconv.LSPLineMap {
return lineMap
})

Expand Down
Loading