Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Ensure absolute file paths for diagnostics #77

Merged
merged 1 commit into from
Feb 8, 2017

Conversation

ryanashcraft
Copy link

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:

screen shot 2017-02-04 at 11 18 28 am

I've dug into this a bit, and it seems the issue is related to a bad assumption that flow status --json always 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 with vscode.Uri.file, which expects absolute paths and results in an invalid URI.

This change ensures that the file path is always absolute, leveraging the flowRoot value from flowFindDiagnostics, before converting it into a URI with vscode.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-level src directory to be treated as a module root using module.system.node.resolve_dirname=src. We do this so that we can import our own modules similarly to how we import modules from node_modules. For example, importing components/AddToDashboardSelect/AddToDashboardSelect resolves to <PROJECT_ROOT>/src/components/AddToDashboardSelect/AddToDashboardSelect.

Sample output from ./node_modules/.bin/flow status --json for 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
},

@facebook-github-bot
Copy link
Contributor

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.

@orta
Copy link
Contributor

orta commented Feb 5, 2017

Looks pretty 👍 to me - can you please add a CHANGELOG entry too

@ryanashcraft ryanashcraft force-pushed the diagnostic-path-fix branch 2 times, most recently from 9cbf815 to 53d307b Compare February 6, 2017 17:05
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@ryanashcraft
Copy link
Author

@orta updated CHANGELOG

@orta
Copy link
Contributor

orta commented Feb 8, 2017

👍

@orta orta merged commit 96b2703 into flow:master Feb 8, 2017
@ryanashcraft
Copy link
Author

Thanks @orta!

@orta
Copy link
Contributor

orta commented Feb 8, 2017

Thanks to you for contributing @ryanashcraft

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants