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
1 change: 0 additions & 1 deletion internal/fourslash/_scripts/failingTests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ TestDoubleUnderscoreCompletions
TestEditJsdocType
TestExportDefaultClass
TestExportDefaultFunction
TestFindAllRefsForDefaultExport03
TestFindAllRefsForModule
TestFindAllRefsModuleDotExports
TestFindReferencesBindingPatternInJsdocNoCrash1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestFindAllRefsForDefaultExport03(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `/*1*/function /*2*/f() {
return 100;
Expand Down
6 changes: 6 additions & 0 deletions internal/ls/source_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ func (l *LanguageService) getMappedLocation(fileName string, fileRange core.Text
}
}
endPos := l.tryGetSourcePosition(fileName, core.TextPos(fileRange.End()))
if endPos == nil {
endPos = &sourcemap.DocumentPosition{
FileName: startPos.FileName,
Pos: startPos.Pos + fileRange.Len(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks right as a port, but since this is happening, do we need to ensure this position is inside the length of the file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure; my understanding is that the conversion to an LSP range will clamp it via the line map, but maybe not... I can grab the script and min the text length.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like PositionToLineAndCharacter will crash with a slice range out of bounds when rescanning the line for the UTF-16 character offset. Maybe it’s worth adding a guard there and not worrying about it here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I can. I'm questioning whether or not it's a good idea, though, given we don't do the same sort of bounds checks when going from an LSP position to a byte position... Could go either way. Either way it's sort of papering over something.

}
}
debug.Assert(endPos.FileName == startPos.FileName, "start and end should be in same file")
newRange := core.NewTextRange(startPos.Pos, endPos.Pos)
lspRange := l.createLspRangeFromRange(newRange, l.getScript(startPos.FileName))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// === findAllReferences ===
// === /findAllRefsForDefaultExport03.ts ===
// /*FIND ALL REFS*/function [|f|]() {
// return 100;
// }
//
// export default [|f|];
//
// var x: typeof [|f|];
//
// var y = [|f|]();
//
// namespace [|f|] {
// var local = 100;
// }



// === findAllReferences ===
// === /findAllRefsForDefaultExport03.ts ===
// function /*FIND ALL REFS*/[|f|]() {
// return 100;
// }
//
// export default [|f|];
//
// var x: typeof [|f|];
//
// var y = [|f|]();
//
// namespace [|f|] {
// var local = 100;
// }



// === findAllReferences ===
// === /findAllRefsForDefaultExport03.ts ===
// function [|f|]() {
// return 100;
// }
//
// /*FIND ALL REFS*/export default [|f|];
//
// var x: typeof [|f|];
//
// var y = [|f|]();
//
// namespace [|f|] {
// var local = 100;
// }



// === findAllReferences ===
// === /findAllRefsForDefaultExport03.ts ===
// function [|f|]() {
// return 100;
// }
//
// export default /*FIND ALL REFS*/[|f|];
//
// var x: typeof [|f|];
//
// var y = [|f|]();
//
// namespace [|f|] {
// var local = 100;
// }



// === findAllReferences ===
// === /findAllRefsForDefaultExport03.ts ===
// function [|f|]() {
// return 100;
// }
//
// export default [|f|];
//
// var x: typeof /*FIND ALL REFS*/[|f|];
//
// var y = [|f|]();
//
// namespace [|f|] {
// var local = 100;
// }



// === findAllReferences ===
// === /findAllRefsForDefaultExport03.ts ===
// function [|f|]() {
// return 100;
// }
//
// export default [|f|];
//
// var x: typeof [|f|];
//
// var y = /*FIND ALL REFS*/[|f|]();
//
// namespace [|f|] {
// var local = 100;
// }



// === findAllReferences ===
// === /findAllRefsForDefaultExport03.ts ===
// function [|f|]() {
// return 100;
// }
//
// export default [|f|];
//
// var x: typeof [|f|];
//
// var y = [|f|]();
//
// /*FIND ALL REFS*/namespace [|f|] {
// var local = 100;
// }



// === findAllReferences ===
// === /findAllRefsForDefaultExport03.ts ===
// function [|f|]() {
// return 100;
// }
//
// export default [|f|];
//
// var x: typeof [|f|];
//
// var y = [|f|]();
//
// namespace /*FIND ALL REFS*/[|f|] {
// var local = 100;
// }