Skip to content
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

Enable click to go to error in console #5624

Closed
wants to merge 6 commits into from
Closed

Enable click to go to error in console #5624

wants to merge 6 commits into from

Conversation

johnnyreilly
Copy link
Contributor

@johnnyreilly johnnyreilly commented Oct 30, 2018

At present when using CRA with TypeScript, you can click on an error in the console and go to the erroring file. This is great!

not-jumping-to-the-error

What would be even better, is if you went directly to the line and column where the error is happening like this:

jumping-to-the-error

This PR enables this by augmenting the output in the typescriptFormatter. There is some duplication in the console as webpack already displays the filepath alone.

Certainly for myself, I'd take this duplication to unlock the ability to click and go directly to an error. (This is what the default formatter in fork-ts-checker-webpack-plugin does.)

What do you think?

@Timer
Copy link
Contributor

Timer commented Oct 30, 2018

I thought VS Code supported this without a full path, assuming the path matches the workspace folder opened in VS Code. Does it need to be prefixed with ./?

@johnnyreilly
Copy link
Contributor Author

johnnyreilly commented Oct 30, 2018

Does it need to be prefixed with ./?

Sorry I don't follow you? What's the thing that is prefixed with ./?

I see the same path webpack outputs repeated with (lineNumber,columnNumber) suffixed.

Feel like I've missed your meaning? (I'm on my phone - perhaps GitHub is hiding something from me 😄)

@Timer
Copy link
Contributor

Timer commented Oct 30, 2018

Sorry, I can try to explain better!

I thought VSCode supported "Click to open" with relative paths, i.e. ./src/App.tsx instead of full paths (C:\Work\my-app\src\App.tsx).

I'm all good for adding (lineNumber,columnNumber), I just don't want to add the C:\....

@weswigham
Copy link

Yeah, vscode supports relative paths in its terminal. You don't need the leading ./, either, something like tests/cases/compiler/declarationEmitQualifiedAliasTypeArgument.ts works fine.

@johnnyreilly
Copy link
Contributor Author

johnnyreilly commented Oct 30, 2018

Awesome! Only problem: how do I get the workspace location in the context of the typescriptFormatter? If I have that I should be able to pare it back to a relative path.

Can I depend upon process.cwd() or __dirname?

@weswigham
Copy link

I think process.cwd()'s a pretty good heuristic, usually. Most of the time scripts get executed in the workspace root, from my experience.

@johnnyreilly
Copy link
Contributor Author

Thanks - I'll experiment with that and report back

@Timer
Copy link
Contributor

Timer commented Oct 30, 2018

@johnnyreilly import config/paths.js and use appPath, probably will need to pass it to constructor when making formatter.

@johnnyreilly
Copy link
Contributor Author

cheers @Timer - will have a play

@johnnyreilly
Copy link
Contributor Author

Hey @Timer,

I've made the suggested change; here's what it looks like with it in place:

screenshot 2018-11-03 16 51 19

@ianschmitz
Copy link
Contributor

Looking good! Perhaps we should strip the leading slash?

@Timer
Copy link
Contributor

Timer commented Nov 3, 2018

We need to somehow morph this path with the (above) highlighted line.

@johnnyreilly
Copy link
Contributor Author

Looking good! Perhaps we should strip the leading slash?

Yeah could do

We need to somehow morph this path with the (above) highlighted line.

I would love to do that! Alas, unless I've misunderstood things, the (above) highlighted line is not part of the formatter output. It's emitted by webpack I think.

Do you know a way to control that?

@Timer
Copy link
Contributor

Timer commented Nov 3, 2018

We control that output here:
https://github.com/facebook/create-react-app/blob/master/packages/react-dev-utils/formatWebpackMessages.js

We should be able to teach it the necessary trick there. :-)

@johnnyreilly
Copy link
Contributor Author

Nice, nice!

Will experiment...

@johnnyreilly
Copy link
Contributor Author

Hmmm... There's a number of call sites.

Should be fine:

const messages = formatWebpackMessages(

Should be fine, this file already imports ./config/paths:

messages = formatWebpackMessages({

messages = formatWebpackMessages(

But I'm not sure how to make this work nicely:

var formatted = formatWebpackMessages({

var formatted = formatWebpackMessages({

Any ideas?

@johnnyreilly
Copy link
Contributor Author

johnnyreilly commented Nov 4, 2018

The issue being the way webpackHotDevClient is referenced in webpack.config.dev.js:

require.resolve('react-dev-utils/webpackHotDevClient'),

require.resolve('react-dev-utils/webpackHotDevClient'),

Is there a nice way that appPath be passed to webpackHotDevClient?

@johnnyreilly
Copy link
Contributor Author

@ianschmitz / @Timer - any thoughts on how I can advance this?

@Timer
Copy link
Contributor

Timer commented Nov 8, 2018

Hey @johnnyreilly, I'm a little tight on time right now so I need to defer to some other collaborators.

I'm very interested in moving this forward though (and will get around to it eventually if someone else doesn't).

@johnnyreilly
Copy link
Contributor Author

That's cool @Timer - when you're ready then let me know!

@ianschmitz
Copy link
Contributor

Yeah I've been looking at it for a little while - this is a tricky one...

Taking a step back, could we do something as simple as stripping out everything before src/...? I haven't put much thought into if that breaks support somewhere or if eject would still work...

@johnnyreilly
Copy link
Contributor Author

Taking a step back, could we do something as simple as stripping out everything before src/...? I haven't put much thought into if that breaks support somewhere or if eject would still work...

Sounds possible; like you I've no idea of the answers to the questions.

@alexkuz
Copy link

alexkuz commented Nov 28, 2018

@johnnyreilly As I understand this PR only deals with TypeScript, shouldn't we also use filename(line,col) format in JS projects?

Also it's probably better to use filename:line:col format rather than filename(line,col) - for example, iTerm works fine with the former when I'm clicking on it but ignores parenthesis in the latter.

BTW you might be interested in how they did it in TSLint: palantir/tslint#3491

@johnnyreilly
Copy link
Contributor Author

johnnyreilly commented Nov 28, 2018

As I understand this PR only deals with TypeScript, shouldn't we also use filename(line,col) format in JS projects?

This should cater for both js and ts - files; TypeScript will check both and produce errors for either; this just handles the formatting. It's labelled as TypeScript specific as we only start using TypeScript to identify errors in TypeScript and JavaScript when you add a TypeScript file to the project.

Also it's probably better to use filename:line:col format rather than filename(line,col)

In my experience the filename(line,col) format has more widespread support. I used to have a good link detailing stuff about error formatting - lost it alas. Either way, the cool thing about fork-ts-checker-webpack-plugin is that if you want to supply your own formatter you can!

@alexkuz
Copy link

alexkuz commented Nov 29, 2018

Either way, the cool thing about fork-ts-checker-webpack-plugin is that if you want to supply your own formatter you can!

But I'd need to eject for that, right? I'll better try to convince iTerm maintainers to support filename(line,col) format :)

@ianschmitz ianschmitz self-requested a review December 7, 2018 06:20
@alexkuz
Copy link

alexkuz commented Dec 15, 2018

if anyone interested, iTerm2 now supports filename(line,col) format (it's not published yet, as far as I know) - kudos to @gnachman for his awesome work and quick response.

@stale
Copy link

stale bot commented Jan 18, 2019

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Jan 18, 2019
@johnnyreilly
Copy link
Contributor Author

I'd quite like to get this in - I'm waiting on advice on how to take this forward.

@stale stale bot removed the stale label Jan 18, 2019
@stale
Copy link

stale bot commented Feb 17, 2019

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Feb 17, 2019
@johnnyreilly
Copy link
Contributor Author

Could someone advise on how we could take this forward please?

@stale stale bot removed the stale label Feb 17, 2019
@iansu iansu added this to the 2.x milestone Feb 17, 2019
@ianschmitz
Copy link
Contributor

I've taken a look at webpackHotDevClient and it doesn't seem like there is an easy way to get appPath into the formatter. I'd be okay with using process.cwd() as a first pass to get this in as it will be a great improvement that should work well for most everyone. Worst case I imagine is if the user is running from some subdirectory for whatever reason, we wouldn't strip off the absolute path leading up to src/, which is not the end of the world.

We can create a separate issue to figure out a better way where we can use appPath.

@johnnyreilly
Copy link
Contributor Author

Cool - when I get a moment I'll give it a go!

@johnnyreilly
Copy link
Contributor Author

okay - merging is a world of pain. I regret even attempting this. I'll fork and apply my changes to that

@johnnyreilly
Copy link
Contributor Author

Closing in favour of #6502

@lock lock bot locked and limited conversation to collaborators Feb 28, 2019
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.

7 participants