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
8 changes: 4 additions & 4 deletions internal/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,17 +557,17 @@ func GetScriptKindFromFileName(fileName string) ScriptKind {
//
// @internal
func GetSpellingSuggestion[T any](name string, candidates iter.Seq[T], getName func(T) string, compare func(T, T) int) T {
maximumLengthDifference := max(2, int(float64(len(name))*0.34))
bestDistance := math.Floor(float64(len(name))*0.4) + 0.9 // If the best result is worse than this, don't bother.
runeName := []rune(name)
maximumLengthDifference := max(2, int(float64(len(runeName))*0.34))
bestDistance := math.Floor(float64(len(runeName))*0.4) + 0.9 // If the best result is worse than this, don't bother.
buffers := levenshteinBuffersPool.Get().(*levenshteinBuffers)
defer levenshteinBuffersPool.Put(buffers)
var bestCandidate T
hasBest := false
for candidate := range candidates {
candidateName := getName(candidate)
maxLen := max(len(candidateName), len(name))
minLen := min(len(candidateName), len(name))
maxLen := max(len(candidateName), len(runeName))
minLen := min(len(candidateName), len(runeName))
if candidateName != "" && maxLen-minLen <= maximumLengthDifference {
if candidateName == name {
continue
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
unicodeSpellingSuggestions.ts(3,1): error TS1435: Unknown keyword or identifier. Did you mean 'class'?
unicodeSpellingSuggestions.ts(3,1): error TS2304: Cannot find name 'classAé'.
unicodeSpellingSuggestions.ts(6,1): error TS1435: Unknown keyword or identifier. Did you mean 'class Aéé'?
unicodeSpellingSuggestions.ts(6,1): error TS2304: Cannot find name 'classAéé'.
unicodeSpellingSuggestions.ts(9,1): error TS1435: Unknown keyword or identifier. Did you mean 'class Aééé'?
unicodeSpellingSuggestions.ts(9,1): error TS2304: Cannot find name 'classAééé'.


==== unicodeSpellingSuggestions.ts (6 errors) ====
// https://github.com/microsoft/typescript-go/issues/4223

classAé {
~~~~~~~
!!! error TS1435: Unknown keyword or identifier. Did you mean 'class'?
~~~~~~~
!!! error TS2304: Cannot find name 'classAé'.
}

classAéé {
~~~~~~~~
!!! error TS1435: Unknown keyword or identifier. Did you mean 'class Aéé'?
~~~~~~~~
!!! error TS2304: Cannot find name 'classAéé'.
}

classAééé {
~~~~~~~~~
!!! error TS1435: Unknown keyword or identifier. Did you mean 'class Aééé'?
~~~~~~~~~
!!! error TS2304: Cannot find name 'classAééé'.
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//// [tests/cases/compiler/unicodeSpellingSuggestions.ts] ////

=== unicodeSpellingSuggestions.ts ===

// https://github.com/microsoft/typescript-go/issues/4223

classAé {
}

classAéé {
}

classAééé {
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//// [tests/cases/compiler/unicodeSpellingSuggestions.ts] ////

=== unicodeSpellingSuggestions.ts ===
// https://github.com/microsoft/typescript-go/issues/4223

classAé {
>classAé : any
}

classAéé {
>classAéé : any
}

classAééé {
>classAééé : any
}

12 changes: 12 additions & 0 deletions testdata/tests/cases/compiler/unicodeSpellingSuggestions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @noEmit: true

// https://github.com/microsoft/typescript-go/issues/4223

classAé {
}

classAéé {
}

classAééé {
}
Loading