Skip to content

Commit 2244ceb

Browse files
ayazhafizKeen Yee Liau
authored andcommitted
fix(server): don't skip definitions with a zero-length range
Certain definition files (like CSS files) don't have a `scriptInfo` but also don't need to be read, because their definition spans are of 0 length. Don't skip over such definitions.
1 parent 49900e1 commit 2244ceb

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

server/src/server.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,18 @@ connection.onDefinition((params: lsp.TextDocumentPositionParams) => {
168168
const results: lsp.LocationLink[] = [];
169169
for (const d of definition.definitions) {
170170
const scriptInfo = tsProjSvc.getScriptInfo(d.fileName);
171-
if (!scriptInfo) {
171+
172+
// Some definitions, like definitions of CSS files, may not be recorded files with a
173+
// `scriptInfo` but are still valid definitions because they are files that exist. In this case,
174+
// check to make sure that the text span of the definition is zero so that the file doesn't have
175+
// to be read; if the span is non-zero, we can't do anything with this definition.
176+
if (!scriptInfo && d.textSpan.length > 0) {
172177
continue;
173178
}
179+
const ZERO_RANGE = lsp.Range.create(0, 0, 0, 0); // for files without `scriptInfo`
180+
const range = scriptInfo ? tsTextSpanToLspRange(scriptInfo, d.textSpan) : ZERO_RANGE;
181+
174182
const targetUri = filePathToUri(d.fileName);
175-
const range = tsTextSpanToLspRange(scriptInfo, d.textSpan);
176183
results.push({
177184
originSelectionRange,
178185
targetUri,

0 commit comments

Comments
 (0)