Skip to content

Commit ea5773a

Browse files
committed
fix
1 parent 410900e commit ea5773a

File tree

8 files changed

+48
-54
lines changed

8 files changed

+48
-54
lines changed

internal/core/textchange.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ func ApplyBulkEdits(text string, edits []TextChange) string {
1616
b.Grow(len(text))
1717
lastEnd := 0
1818
for _, e := range edits {
19-
start := e.TextRange.Pos()
19+
start := e.Pos()
2020
if start != lastEnd {
21-
b.WriteString(text[lastEnd:e.TextRange.Pos()])
21+
b.WriteString(text[lastEnd:e.Pos()])
2222
}
2323
b.WriteString(e.NewText)
2424

25-
lastEnd = e.TextRange.End()
25+
lastEnd = e.End()
2626
}
2727
b.WriteString(text[lastEnd:])
2828

internal/execute/tsctests/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (test *tscInput) run(t *testing.T, scenario string) {
122122
unexpectedDiff += fmt.Sprintf("Edit [%d]:: %s\n!!! Unexpected diff, please review and either fix or write explanation as expectedDiff !!!\n%s\n", index, do.caption, diff)
123123
}
124124
} else if do.expectedDiff != "" {
125-
baselineBuilder.WriteString(fmt.Sprintf("\n\nDiff:: %s !!! Diff not found but explanation present, please review and remove the explanation !!!\n", do.expectedDiff))
125+
fmt.Fprintf(baselineBuilder, "\n\nDiff:: %s !!! Diff not found but explanation present, please review and remove the explanation !!!\n", do.expectedDiff)
126126
unexpectedDiff += fmt.Sprintf("Edit [%d]:: %s\n!!! Diff not found but explanation present, please review and remove the explanation !!!\n", index, do.caption)
127127
}
128128
}

internal/execute/tsctests/tscbuild_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,7 @@ func TestBuildProjectReferenceWithRootDirInParent(t *testing.T) {
22662266
subScenario: "reports error for same tsbuildinfo file because no rootDir in the base",
22672267
files: getBuildProjectReferenceWithRootDirInParentFileMap(
22682268
func(files FileMap) {
2269-
text, _ := files["/home/src/workspaces/solution/tsconfig.base.json"]
2269+
text := files["/home/src/workspaces/solution/tsconfig.base.json"]
22702270
files["/home/src/workspaces/solution/tsconfig.base.json"] = strings.Replace(text.(string), `"rootDir": "./src/",`, "", 1)
22712271
},
22722272
),
@@ -2514,21 +2514,21 @@ func TestBuildResolveJsonModule(t *testing.T) {
25142514
tsconfigFiles: `"include": [ "src/**/*" ],`,
25152515
additionalCompilerOptions: `"rootDir": "src",`,
25162516
modifyFiles: func(files FileMap) {
2517-
text, _ := files["/home/src/workspaces/solution/project/src/hello.json"]
2517+
text := files["/home/src/workspaces/solution/project/src/hello.json"]
25182518
delete(files, "/home/src/workspaces/solution/project/src/hello.json")
25192519
files["/home/src/workspaces/solution/project/hello.json"] = text
2520-
text, _ = files["/home/src/workspaces/solution/project/src/index.ts"]
2520+
text = files["/home/src/workspaces/solution/project/src/index.ts"]
25212521
files["/home/src/workspaces/solution/project/src/index.ts"] = strings.Replace(text.(string), "./hello.json", "../hello.json", 1)
25222522
},
25232523
},
25242524
{
25252525
subScenario: "include only with json without rootDir but outside configDirectory",
25262526
tsconfigFiles: `"include": [ "src/**/*" ],`,
25272527
modifyFiles: func(files FileMap) {
2528-
text, _ := files["/home/src/workspaces/solution/project/src/hello.json"]
2528+
text := files["/home/src/workspaces/solution/project/src/hello.json"]
25292529
delete(files, "/home/src/workspaces/solution/project/src/hello.json")
25302530
files["/home/src/workspaces/solution/hello.json"] = text
2531-
text, _ = files["/home/src/workspaces/solution/project/src/index.ts"]
2531+
text = files["/home/src/workspaces/solution/project/src/index.ts"]
25322532
files["/home/src/workspaces/solution/project/src/index.ts"] = strings.Replace(text.(string), "./hello.json", "../../hello.json", 1)
25332533
},
25342534
},
@@ -2540,10 +2540,10 @@ func TestBuildResolveJsonModule(t *testing.T) {
25402540
subScenario: "include of json along with other include and file name matches ts file",
25412541
tsconfigFiles: `"include": [ "src/**/*", "src/**/*.json" ],`,
25422542
modifyFiles: func(files FileMap) {
2543-
text, _ := files["/home/src/workspaces/solution/project/src/hello.json"]
2543+
text := files["/home/src/workspaces/solution/project/src/hello.json"]
25442544
delete(files, "/home/src/workspaces/solution/project/src/hello.json")
25452545
files["/home/src/workspaces/solution/project/src/index.json"] = text
2546-
text, _ = files["/home/src/workspaces/solution/project/src/index.ts"]
2546+
text = files["/home/src/workspaces/solution/project/src/index.ts"]
25472547
files["/home/src/workspaces/solution/project/src/index.ts"] = strings.Replace(text.(string), "./hello.json", "./index.json", 1)
25482548
},
25492549
},
@@ -2937,7 +2937,7 @@ func TestBuildSample(t *testing.T) {
29372937
{
29382938
subScenario: "skips builds downstream projects if upstream projects have errors with stopBuildOnErrors",
29392939
files: getBuildSampleFileMap(func(files FileMap) {
2940-
text, _ := files["/user/username/projects/sample1/core/index.ts"]
2940+
text := files["/user/username/projects/sample1/core/index.ts"]
29412941
files["/user/username/projects/sample1/core/index.ts"] = text.(string) + `multiply();`
29422942
}),
29432943
cwd: "/user/username/projects/sample1",
@@ -2969,7 +2969,7 @@ func TestBuildSample(t *testing.T) {
29692969
"skipDefaultLibCheck": true,
29702970
},
29712971
}`)
2972-
text, _ := files["/user/username/projects/sample1/core/index.ts"]
2972+
text := files["/user/username/projects/sample1/core/index.ts"]
29732973
files["/user/username/projects/sample1/core/index.ts"] = text.(string) + `multiply();`
29742974
}),
29752975
cwd: "/user/username/projects/sample1",
@@ -3152,7 +3152,7 @@ class someClass2 { }`,
31523152
{
31533153
subScenario: "builds correctly when project is not composite or doesnt have any references",
31543154
files: getBuildSampleFileMap(func(files FileMap) {
3155-
text, _ := files["/user/username/projects/sample1/core/tsconfig.json"]
3155+
text := files["/user/username/projects/sample1/core/tsconfig.json"]
31563156
files["/user/username/projects/sample1/core/tsconfig.json"] = strings.Replace(text.(string), `"composite": true,`, "", 1)
31573157
}),
31583158
cwd: "/user/username/projects/sample1",
@@ -3332,7 +3332,7 @@ class someClass2 { }`,
33323332
"target": "es5"
33333333
}
33343334
}`)
3335-
text, _ := files["/user/username/projects/sample1/tests/tsconfig.json"]
3335+
text := files["/user/username/projects/sample1/tests/tsconfig.json"]
33363336
files["/user/username/projects/sample1/tests/tsconfig.json"] = strings.Replace(text.(string), `"references": [`, `"extends": "./tsconfig.base.json", "references": [`, 1)
33373337
}),
33383338
cwd: "/user/username/projects/sample1",
@@ -3358,7 +3358,7 @@ class someClass2 { }`,
33583358
{
33593359
subScenario: "builds downstream projects even if upstream projects have errors",
33603360
files: getBuildSampleFileMap(func(files FileMap) {
3361-
text, _ := files["/user/username/projects/sample1/logic/index.ts"]
3361+
text := files["/user/username/projects/sample1/logic/index.ts"]
33623362
files["/user/username/projects/sample1/logic/index.ts"] = strings.Replace(text.(string), "c.multiply(10, 15)", `c.muitply()`, 1)
33633363
}),
33643364
cwd: "/user/username/projects/sample1",
@@ -3412,7 +3412,7 @@ class someClass2 { }`,
34123412
{
34133413
subScenario: "when logic specifies tsBuildInfoFile",
34143414
files: getBuildSampleFileMap(func(files FileMap) {
3415-
text, _ := files["/user/username/projects/sample1/logic/tsconfig.json"]
3415+
text := files["/user/username/projects/sample1/logic/tsconfig.json"]
34163416
files["/user/username/projects/sample1/logic/tsconfig.json"] = strings.Replace(
34173417
text.(string),
34183418
`"composite": true,`,

internal/ls/autoimportfixes.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (ct *changeTracker) doAddExistingFix(
7777

7878
if defaultImport != nil {
7979
debug.Assert(clause.Name() == nil, "Cannot add a default import to an import clause that already has one")
80-
ct.insertNodeAt(sourceFile, core.TextPos(astnav.GetStartOfNode(clause, sourceFile, false)), ct.NodeFactory.NewIdentifier(defaultImport.name), changeNodeOptions{suffix: ", "})
80+
ct.insertNodeAt(sourceFile, core.TextPos(astnav.GetStartOfNode(clause, sourceFile, false)), ct.NewIdentifier(defaultImport.name), changeNodeOptions{suffix: ", "})
8181
}
8282

8383
if len(namedImports) > 0 {
@@ -88,10 +88,10 @@ func (ct *changeTracker) doAddExistingFix(
8888
if namedImport.propertyName != "" {
8989
identifier = ct.NodeFactory.NewIdentifier(namedImport.propertyName).AsIdentifier().AsNode()
9090
}
91-
return ct.NodeFactory.NewImportSpecifier(
91+
return ct.NewImportSpecifier(
9292
(!importClause.IsTypeOnly || promoteFromTypeOnly) && shouldUseTypeOnly(namedImport.addAsTypeOnly, preferences),
9393
identifier,
94-
ct.NodeFactory.NewIdentifier(namedImport.name),
94+
ct.NewIdentifier(namedImport.name),
9595
)
9696
}) // !!! sort with specifierComparer
9797

@@ -137,7 +137,7 @@ func (ct *changeTracker) doAddExistingFix(
137137
}
138138
} else {
139139
if len(newSpecifiers) > 0 {
140-
namedImports := ct.NodeFactory.NewNamedImports(ct.NodeFactory.NewNodeList(newSpecifiers))
140+
namedImports := ct.NewNamedImports(ct.NewNodeList(newSpecifiers))
141141
if importClause.NamedBindings != nil {
142142
ct.replaceNode(sourceFile, importClause.NamedBindings, namedImports, nil)
143143
} else {
@@ -174,22 +174,22 @@ func (ct *changeTracker) addElementToBindingPattern(sourceFile *ast.SourceFile,
174174
if len(bindingPattern.Elements()) > 0 {
175175
ct.insertNodeInListAfter(sourceFile, bindingPattern.Elements()[len(bindingPattern.Elements())-1], element, nil)
176176
} else {
177-
ct.replaceNode(sourceFile, bindingPattern, ct.NodeFactory.NewBindingPattern(
177+
ct.replaceNode(sourceFile, bindingPattern, ct.NewBindingPattern(
178178
ast.KindObjectBindingPattern,
179-
ct.NodeFactory.NewNodeList([]*ast.Node{element}),
179+
ct.NewNodeList([]*ast.Node{element}),
180180
), nil)
181181
}
182182
}
183183

184184
func (ct *changeTracker) newBindingElementFromNameAndPropertyName(name string, propertyName *string) *ast.Node {
185185
var newPropertyNameIdentifier *ast.Node
186186
if propertyName != nil {
187-
newPropertyNameIdentifier = ct.NodeFactory.NewIdentifier(*propertyName)
187+
newPropertyNameIdentifier = ct.NewIdentifier(*propertyName)
188188
}
189-
return ct.NodeFactory.NewBindingElement(
189+
return ct.NewBindingElement(
190190
nil, /*dotDotDotToken*/
191191
newPropertyNameIdentifier,
192-
ct.NodeFactory.NewIdentifier(name),
192+
ct.NewIdentifier(name),
193193
nil, /* initializer */
194194
)
195195
}
@@ -241,13 +241,13 @@ func (ct *changeTracker) insertImports(sourceFile *ast.SourceFile, imports []*as
241241
func (ct *changeTracker) makeImport(defaultImport *ast.IdentifierNode, namedImports []*ast.Node, moduleSpecifier *ast.Expression, isTypeOnly bool) *ast.Statement {
242242
var newNamedImports *ast.Node
243243
if len(namedImports) > 0 {
244-
newNamedImports = ct.NodeFactory.NewNamedImports(ct.NodeFactory.NewNodeList(namedImports))
244+
newNamedImports = ct.NewNamedImports(ct.NewNodeList(namedImports))
245245
}
246246
var importClause *ast.Node
247247
if defaultImport != nil || newNamedImports != nil {
248-
importClause = ct.NodeFactory.NewImportClause(isTypeOnly, defaultImport, newNamedImports)
248+
importClause = ct.NewImportClause(isTypeOnly, defaultImport, newNamedImports)
249249
}
250-
return ct.NodeFactory.NewImportDeclaration( /*modifiers*/ nil, importClause, moduleSpecifier, nil /*attributes*/)
250+
return ct.NewImportDeclaration( /*modifiers*/ nil, importClause, moduleSpecifier, nil /*attributes*/)
251251
}
252252

253253
func (ct *changeTracker) getNewImports(
@@ -259,7 +259,7 @@ func (ct *changeTracker) getNewImports(
259259
compilerOptions *core.CompilerOptions,
260260
preferences *UserPreferences,
261261
) []*ast.Statement {
262-
moduleSpecifierStringLiteral := ct.NodeFactory.NewStringLiteral(moduleSpecifier)
262+
moduleSpecifierStringLiteral := ct.NewStringLiteral(moduleSpecifier)
263263
var statements []*ast.Statement // []AnyImportSyntax
264264
if defaultImport != nil || len(namedImports) > 0 {
265265
// `verbatimModuleSyntax` should prefer top-level `import type` -
@@ -271,38 +271,38 @@ func (ct *changeTracker) getNewImports(
271271

272272
var defaultImportNode *ast.Node
273273
if defaultImport != nil {
274-
defaultImportNode = ct.NodeFactory.NewIdentifier(defaultImport.name)
274+
defaultImportNode = ct.NewIdentifier(defaultImport.name)
275275
}
276276

277277
statements = append(statements, ct.makeImport(defaultImportNode, core.Map(namedImports, func(namedImport *Import) *ast.Node {
278278
var namedImportPropertyName *ast.Node
279279
if namedImport.propertyName != "" {
280-
namedImportPropertyName = ct.NodeFactory.NewIdentifier(namedImport.propertyName)
280+
namedImportPropertyName = ct.NewIdentifier(namedImport.propertyName)
281281
}
282-
return ct.NodeFactory.NewImportSpecifier(
282+
return ct.NewImportSpecifier(
283283
!topLevelTypeOnly && shouldUseTypeOnly(namedImport.addAsTypeOnly, preferences),
284284
namedImportPropertyName,
285-
ct.NodeFactory.NewIdentifier(namedImport.name),
285+
ct.NewIdentifier(namedImport.name),
286286
)
287287
}), moduleSpecifierStringLiteral, topLevelTypeOnly))
288288
}
289289

290290
if namespaceLikeImport != nil {
291291
var declaration *ast.Statement
292292
if namespaceLikeImport.kind == ImportKindCommonJS {
293-
declaration = ct.NodeFactory.NewImportEqualsDeclaration(
293+
declaration = ct.NewImportEqualsDeclaration(
294294
/*modifiers*/ nil,
295295
shouldUseTypeOnly(namespaceLikeImport.addAsTypeOnly, preferences),
296-
ct.NodeFactory.NewIdentifier(namespaceLikeImport.name),
297-
ct.NodeFactory.NewExternalModuleReference(moduleSpecifierStringLiteral),
296+
ct.NewIdentifier(namespaceLikeImport.name),
297+
ct.NewExternalModuleReference(moduleSpecifierStringLiteral),
298298
)
299299
} else {
300-
declaration = ct.NodeFactory.NewImportDeclaration(
300+
declaration = ct.NewImportDeclaration(
301301
/*modifiers*/ nil,
302-
ct.NodeFactory.NewImportClause(
302+
ct.NewImportClause(
303303
shouldUseTypeOnly(namespaceLikeImport.addAsTypeOnly, preferences),
304304
/*name*/ nil,
305-
ct.NodeFactory.NewNamespaceImport(ct.NodeFactory.NewIdentifier(namespaceLikeImport.name)),
305+
ct.NewNamespaceImport(ct.NewIdentifier(namespaceLikeImport.name)),
306306
),
307307
moduleSpecifierStringLiteral,
308308
/*attributes*/ nil,

internal/ls/autoimports.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,7 @@ func (l *LanguageService) getImportCompletionAction(
380380
// formatContext *formattingContext,
381381
preferences *UserPreferences,
382382
) (string, codeAction) {
383-
var exportInfos []*SymbolExportInfo
384-
// `exportMapKey` should be in the `itemData` of each auto-import completion entry and sent in resolving completion entry requests
385-
exportInfos = l.getExportInfos(ctx, ch, sourceFile, preferences, exportMapKey)
383+
var exportInfos []*SymbolExportInfo = l.getExportInfos(ctx, ch, sourceFile, preferences, exportMapKey)
386384
if len(exportInfos) == 0 {
387385
panic("Some exportInfo should match the specified exportMapKey")
388386
}

internal/ls/changetrackerimpl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (ct *changeTracker) getTextChangesFromChanges() map[string][]*lsproto.TextE
2525
slices.SortStableFunc(changesInFile, func(a, b *trackerEdit) int { return CompareRanges(ptrTo(a.Range), ptrTo(b.Range)) })
2626
// verify that change intervals do not overlap, except possibly at end points.
2727
for i := range len(changesInFile) - 1 {
28-
if ComparePositions(changesInFile[i].Range.End, changesInFile[i+1].Range.Start) > 0 {
28+
if ComparePositions(changesInFile[i].Range.End, changesInFile[i+1].Start) > 0 {
2929
// assert change[i].End <= change[i + 1].Start
3030
panic(fmt.Sprintf("changes overlap: %v and %v", changesInFile[i].Range, changesInFile[i+1].Range))
3131
}
@@ -61,7 +61,7 @@ func (ct *changeTracker) computeNewText(change *trackerEdit, targetSourceFile *a
6161
return change.NewText
6262
}
6363

64-
pos := int(ct.ls.converters.LineAndCharacterToPosition(sourceFile, change.Range.Start))
64+
pos := int(ct.ls.converters.LineAndCharacterToPosition(sourceFile, change.Start))
6565
formatNode := func(n *ast.Node) string {
6666
return ct.getFormattedTextOfNode(n, targetSourceFile, sourceFile, pos, change.options)
6767
}

internal/project/configfileregistrybuilder.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,11 @@ func (c *configFileRegistryBuilder) updateRootFilesWatch(fileName string, entry
168168
wildcardGlobs := entry.commandLine.WildcardDirectories()
169169
rootFileGlobs := make([]string, 0, len(wildcardGlobs)+1+len(entry.commandLine.ExtendedSourceFiles()))
170170
rootFileGlobs = append(rootFileGlobs, fileName)
171-
for _, extendedConfig := range entry.commandLine.ExtendedSourceFiles() {
172-
rootFileGlobs = append(rootFileGlobs, extendedConfig)
173-
}
171+
rootFileGlobs = append(rootFileGlobs, entry.commandLine.ExtendedSourceFiles()...)
174172
for dir, recursive := range wildcardGlobs {
175173
rootFileGlobs = append(rootFileGlobs, fmt.Sprintf("%s/%s", tspath.NormalizePath(dir), core.IfElse(recursive, recursiveFileGlobPattern, fileGlobPattern)))
176174
}
177-
for _, fileName := range entry.commandLine.LiteralFileNames() {
178-
rootFileGlobs = append(rootFileGlobs, fileName)
179-
}
175+
rootFileGlobs = append(rootFileGlobs, entry.commandLine.LiteralFileNames()...)
180176

181177
slices.Sort(rootFileGlobs)
182178
entry.rootFilesWatch = entry.rootFilesWatch.Clone(rootFileGlobs)

internal/transformers/jsxtransforms/jsx.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -840,21 +840,21 @@ var htmlEntityMatcher = regexp2.MustCompile(`&((#((\d+)|x([\da-fA-F]+)))|(\w+));
840840

841841
func htmlEntityReplacer(m regexp2.Match) string {
842842
decimal := m.GroupByNumber(4)
843-
if decimal != nil && decimal.Capture.String() != "" {
843+
if decimal != nil && decimal.String() != "" {
844844
parsed, err := strconv.ParseInt(decimal.String(), 10, 32)
845845
if err == nil {
846846
return string(rune(parsed))
847847
}
848848
}
849849
hex := m.GroupByNumber(5)
850-
if hex != nil && hex.Capture.String() != "" {
850+
if hex != nil && hex.String() != "" {
851851
parsed, err := strconv.ParseInt(hex.String(), 16, 32)
852852
if err == nil {
853853
return string(rune(parsed))
854854
}
855855
}
856856
word := m.GroupByNumber(6)
857-
if word != nil && word.Capture.String() != "" {
857+
if word != nil && word.String() != "" {
858858
res, ok := entities[word.String()]
859859
if ok {
860860
return string(res)

0 commit comments

Comments
 (0)