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

Allow diagnostic and completions in js #337

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Matsuuu
Copy link
Contributor

@Matsuuu Matsuuu commented Sep 15, 2022

This PR builds on top of #336 since the optimization was kind of needed for some of the code changes here too.

If this gets merged, we don't need to merge #336 since this was branched from it and the commit is here too.

The PR is quite simple in general: We just add JS as the allowed filetype in a couple of places and inform TS that javascript files should also be handled.

Then instead of just yielding the JS files in processTypeScriptFiles we also add it to the compilerinputs. It will make it so that they are handled in the completions and diagnostics parts of our code, but the won't try to compile them since they're already javascript.

@Matsuuu
Copy link
Contributor Author

Matsuuu commented Sep 20, 2022

Ah it seems that the tests are failing on some javascript specific testings.

I'll need to check those out and iron out some of those still.

@Matsuuu
Copy link
Contributor Author

Matsuuu commented Sep 20, 2022

There might be some cases we want to review here:

One test includes a case "ignores js file", which checks that the JS file doesn't get any diagnostics info etc.

However with this completion + diagnostic update we are getting diagnostic data for JS files and at least IMO that is a plus side.

So... Should we just remove this test? (typescript-worker_test.ts:39)

@Matsuuu
Copy link
Contributor Author

Matsuuu commented Sep 20, 2022

The other failing test seems to be on " compiles jsx file to js" and the reason it fails is because it also gets diagnostics instead of just the compiler output.

Should we just update the expected cases with the corresponding diagnostics info?

Copy link
Member

@aomarks aomarks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, so simple! Very sorry it took so long to review this. Would adding a test be possible?

@@ -10,6 +10,8 @@ import {PackageJson} from './util.js';
import {makeLspDiagnostic} from './diagnostic.js';
import {WorkerContext} from './worker-context.js';

const PROCESSED_FILE_ENDINGS = ['.ts', '.jsx', '.tsx'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const PROCESSED_FILE_ENDINGS = ['.ts', '.jsx', '.tsx'];
const COMPILED_FILE_ENDINGS = ['.ts', '.jsx', '.tsx'];

(Just a nit, since .js is "processed", it's just not compiled)

@@ -20,22 +22,32 @@ export async function* processTypeScriptFiles(
let packageJson: PackageJson | undefined;
const compilerInputs = [];
for await (const result of results) {
if (result.kind !== 'file') continue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (result.kind !== 'file') continue;
if (result.kind !== 'file') {
continue;
}

Style nit

@rwalle
Copy link

rwalle commented Feb 13, 2023

Hi @Matsuuu, is this something that you will be able to work on in the near future? Otherwise I can help continue the work.

@Matsuuu
Copy link
Contributor Author

Matsuuu commented Feb 13, 2023

Hi @Matsuuu, is this something that you will be able to work on in the near future? Otherwise I can help continue the work.

Ah thanks for the nudge @rwalle ! I had sorta forgotten about this. I'll try and set some time aside in the coming week to look into finalizing this. It's mostly just rewriting a couple of tests and testing it out

@@ -632,7 +632,7 @@ export class PlaygroundCodeEditor extends LitElement {
private _currentFiletypeSupportsCompletion() {
// Currently we are only supporting code completion for TS. Change
// this in a case that we start to support it for other languages too.
return this.type === 'ts';
return this.type === 'ts' || this.type === 'js';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also support completions for tsx and jsx?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think we could see if it works out of the box with those too

@Matsuuu
Copy link
Contributor Author

Matsuuu commented May 23, 2023

Heya @aomarks @augustjk !

I think I should grab myself from the bootstraps and get this thing actually finished finally. I remember having some hiccups with the env at the start of the year but I'll try and find some time to finalize this in the coming weeks.

I'm still awaiting a little bit of feedback on some of my previous comments. Namely:


There might be some cases we want to review here:

One test includes a case "ignores js file", which checks that the JS file doesn't get any diagnostics info etc.

However with this completion + diagnostic update we are getting diagnostic data for JS files and at least IMO that is a plus side.

So... Should we just remove this test? (typescript-worker_test.ts:39)


The other failing test seems to be on " compiles jsx file to js" and the reason it fails is because it also gets diagnostics instead of just the compiler output.

Should we just update the expected cases with the corresponding diagnostics info?


So basically both of these cases are just for the past where we didn't expect to have JS support, and also for cases where the diagnostics were lacking. Updating the test cases with the updated info would be beneficial IMO and removing some of the tests that want us to ignore JS would also but beneficial as that's not the case anymore.


After I've gotten some closure on these, I'll try and find a time to finalize the PR and test it out so that we can ship JS (and maybe JS/TS(X) ) completions with the playground!

@augustjk
Copy link
Collaborator

augustjk commented May 23, 2023

Thanks so much @Matsuuu !

  1. I agree "ignore js files" test is no longer relevant and can be removed.
  2. "compiles jsx file to js" should still work without producing error diagnostics.
    I think the mock cdn data for 'react' provided needs to be better and include types too. Something like:
              'index.d.ts': {
                content:
                  'declare export = {createElement(tag: unknown, props: unknown, children: unknown) => unknown;}',
              },

The language service compiler option would need to include allowSyntheticDefaultImports: true to be able to import 'react' with above type declaration. We could do export default instead of export = above to not have to set this option but it's probably good to be a closer match to the real React types.

@Matsuuu
Copy link
Contributor Author

Matsuuu commented May 23, 2023

Yeah agree.

I'll try and take a look at this in the coming weeks. Shouldn't be toomuch of a hassle

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

Successfully merging this pull request may close these issues.

4 participants