Ensure absolute file paths for diagnostics#77
Conversation
|
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks! If you are contributing on behalf of someone else (eg your employer): the individual CLA is not sufficient - use https://developers.facebook.com/opensource/cla?type=company instead. Contact cla@fb.com if you have any questions. |
|
Looks pretty 👍 to me - can you please add a CHANGELOG entry too |
9cbf815 to
53d307b
Compare
53d307b to
9aad44c
Compare
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
|
@orta updated CHANGELOG |
|
👍 |
|
Thanks @orta! |
|
Thanks to you for contributing @ryanashcraft |
I've been experiencing an issue with flow-for-vscode's diagnostics where I'm receiving errors like this when clicking on an error in the "problems" view:
I've dug into this a bit, and it seems the issue is related to a bad assumption that
flow status --jsonalways returns absolute paths. I'm guessing that most flow projects, the paths are absolute. This is the case with flow-for-vscode. However, with my project, the paths are relative to the project root – without a leading./. This causes a problem when the file is converted into a URI withvscode.Uri.file, which expects absolute paths and results in an invalid URI.This change ensures that the file path is always absolute, leveraging the
flowRootvalue fromflowFindDiagnostics, before converting it into a URI withvscode.Uri.file.For additional context, I'm pretty confident I know what is driving this inconsistency with the output of
flow status. My project is configured to treat our top-levelsrcdirectory to be treated as a module root usingmodule.system.node.resolve_dirname=src. We do this so that we can import our own modules similarly to how we import modules fromnode_modules. For example, importingcomponents/AddToDashboardSelect/AddToDashboardSelectresolves to<PROJECT_ROOT>/src/components/AddToDashboardSelect/AddToDashboardSelect.Sample output from
./node_modules/.bin/flow status --jsonfor my project:{ "context": " optionGroups={this.getOptionGroups()}", "descr": "tuple type", "type": "Blame", "loc": { "source": "src/components/AddLegendSeriesSelect/AddLegendSeriesSelect.jsx", "type": "SourceFile", "start": { "line": 62, "column": 31, "offset": 1694 }, "end": { "line": 62, "column": 52, "offset": 1716 } }, "path": "src/components/AddLegendSeriesSelect/AddLegendSeriesSelect.jsx", "line": 62, "endline": 62, "start": 31, "end": 52 },Compared to flow-for-vscode:
{ "context": "\t\tconst line = position.line;", "descr": "property `line`", "type": "Blame", "loc": { "source": "/Users/ryanashcraft/Desktop/flow-for-vscode/lib/flowCompletion.js", "type": "SourceFile", "start": { "line": 31, "column": 25, "offset": 720 }, "end": { "line": 31, "column": 28, "offset": 724 } }, "path": "/Users/ryanashcraft/Desktop/flow-for-vscode/lib/flowCompletion.js", "line": 31, "endline": 31, "start": 25, "end": 28 },