dmmulroy / tsc.nvim

A Neovim plugin for seamless, asynchronous project-wide TypeScript type-checking using the TypeScript compiler (tsc)
MIT License
403 stars 21 forks source link

Pretty ts errors #32

Closed pmwals09 closed 11 months ago

pmwals09 commented 1 year ago

This resolves #7.

The provided test file can be run with :PlenaryBustedFile %.

The MD files are pulled from Matt Pocock's repo, on which this concept was based.

Thanks!

ghost commented 1 year ago

This is amazing!! 💜 🚀 I'm going to review this tonight or tomorrow morning. I've got some ideas to use this PR as the foundation for for some new features for a 2.0 release (more details on that to come)

dmmulroy commented 1 year ago

I'm seeing some issues w/ TS2332 - working debugging now.

I'm seeing this in tsc.nvim:

components/market-dashboards/markets/aave-pool-v2/AavePoolV2DashboardCharts.tsx|181 col 11 error| TS2322: I was expecting a type matching 'data', but instead you passed 'data'.

In vscode I'm seeing:

I was expecting a type matching IntrinsicAttributes & Readonly<{ data: Series | readonly Series[] | unique symbol; option?: Readonly<{ heightPx?: number | undefined; widthPx?: number | undefined; priceFormatter?: PriceFormatterFn | undefined; timeFormatter?: TimeFormatterFn | undefined; }> | undefined; title?: ReactNode; toolbarOptions?: Readonly<..., but instead you passed { data: Readonly<{ kind: "area"; data: readonly SingleValueSeriesDatum[]; options?: Readonly<{ color?: Color | undefined; lastPriceAnimation?: "continuous" | "disabled" | undefined; markers?: readonly SeriesMarker[] | undefined; }> | undefined; }>; options: Readonly<...>; title: Element; toolbarOptions: { ...; }; }.

I've narrowed it down to a bug with these line(s):

    local idx = md_original_message:find(slots[i])
    local match = original_message:match("%w+", idx)

This code assumes that the actual error message will be the same length as the better error message templates. This actually works for better errors with only one slot (b/c the first capture group will always be at the same index as the slot).

I've got some WIP on a solution, but might not get around to finishing it immediately.

pmwals09 commented 1 year ago

@dmmulroy I did some work on this that I pushed up. It's kind of ugly but it gets the job done. I added a test case for the longer error messages you posted above.

Here's a quick overview of what I've put together:

  1. Pull out the text between the slots using the template string from the md file
  2. Iterate a cursor over the message from the compiler, looking forward for the first in-between string from above. While we look, if we don't have a match, that means we're looking at text that belongs in a template slot and capture it in a slot variable for later.
  3. Once we find a match, we save the slot text in slot for our return value, clear out slot for our next capture, and jump the cursor to the end of that in-between string to start looking for the next one.
dmmulroy commented 11 months ago

Made some changes to the implementation to be a bit closer to the implementation in Matt's repo! Sorry this took so long to get reviewed and in, I appreciate all of your effort and work!