-
Notifications
You must be signed in to change notification settings - Fork 714
Port source map position mapping + go to definition source mapping #1767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c920059
source maps + go to def
gabritto 8423ecf
refactor, fix and update tests
gabritto ca93817
refactor
gabritto 672434a
Merge branch 'main' into gabritto/def1
gabritto bb7a5b3
fix typo
gabritto cef9f67
refactor LS host
gabritto c80e7a3
rename line maps with ECMA/LSP
gabritto 4a6c6ea
Merge remote-tracking branch 'origin/gabritto/renamelinemaps' into ga…
gabritto 8debdea
add type alias for line starts
gabritto bd07e42
Merge branch 'main' into gabritto/def1
gabritto 75267d1
remove fileExists from LS host
gabritto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package ls | ||
|
||
import ( | ||
"github.com/microsoft/typescript-go/internal/core" | ||
"github.com/microsoft/typescript-go/internal/debug" | ||
"github.com/microsoft/typescript-go/internal/lsp/lsproto" | ||
"github.com/microsoft/typescript-go/internal/sourcemap" | ||
"github.com/microsoft/typescript-go/internal/tspath" | ||
) | ||
|
||
func (l *LanguageService) getMappedLocation(fileName string, fileRange core.TextRange) lsproto.Location { | ||
startPos := l.tryGetSourcePosition(fileName, core.TextPos(fileRange.Pos())) | ||
if startPos == nil { | ||
lspRange := l.createLspRangeFromRange(fileRange, l.getScript(fileName)) | ||
return lsproto.Location{ | ||
Uri: FileNameToDocumentURI(fileName), | ||
Range: *lspRange, | ||
} | ||
} | ||
endPos := l.tryGetSourcePosition(fileName, core.TextPos(fileRange.End())) | ||
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)) | ||
return lsproto.Location{ | ||
Uri: FileNameToDocumentURI(startPos.FileName), | ||
Range: *lspRange, | ||
} | ||
} | ||
|
||
type script struct { | ||
fileName string | ||
text string | ||
} | ||
|
||
func (s *script) FileName() string { | ||
return s.fileName | ||
} | ||
|
||
func (s *script) Text() string { | ||
return s.text | ||
} | ||
|
||
func (l *LanguageService) getScript(fileName string) *script { | ||
text, ok := l.readFile(fileName) | ||
if !ok { | ||
return nil | ||
} | ||
return &script{fileName: fileName, text: text} | ||
} | ||
|
||
func (l *LanguageService) tryGetSourcePosition( | ||
fileName string, | ||
position core.TextPos, | ||
) *sourcemap.DocumentPosition { | ||
newPos := l.tryGetSourcePositionWorker(fileName, position) | ||
if newPos != nil { | ||
if !l.fileExists(newPos.FileName) { | ||
return nil | ||
} | ||
} | ||
return newPos | ||
} | ||
|
||
func (l *LanguageService) tryGetSourcePositionWorker( | ||
fileName string, | ||
position core.TextPos, | ||
) *sourcemap.DocumentPosition { | ||
if !tspath.IsDeclarationFileName(fileName) { | ||
return nil | ||
} | ||
|
||
positionMapper := l.GetDocumentPositionMapper(fileName) | ||
documentPos := positionMapper.GetSourcePosition(&sourcemap.DocumentPosition{FileName: fileName, Pos: int(position)}) | ||
if documentPos == nil { | ||
return nil | ||
} | ||
if newPos := l.tryGetSourcePositionWorker(documentPos.FileName, core.TextPos(documentPos.Pos)); newPos != nil { | ||
return newPos | ||
} | ||
return documentPos | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.