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

[display] dynamically update the syntax cache #8451

Closed
Gama11 opened this issue Jun 20, 2019 · 10 comments
Closed

[display] dynamically update the syntax cache #8451

Gama11 opened this issue Jun 20, 2019 · 10 comments
Assignees
Labels
enhancement feature-ide IDE / Editor support

Comments

@Gama11
Copy link
Member

Gama11 commented Jun 20, 2019

The completion server has a syntax cache for things like toplevel completion. It is initialized once on startup with server/readClassPaths. The problem is that after this point, it is never updated again.

Here's an example with a newly created Test type, which doesn't show up in completion and thus can't be auto-imported. It only shows up after restarting the language server.

Conversely, Test will still show up after it has been deleted:

To avoid these issues, Haxe needs to update its syntax cache dynamically when types are added or removed. We probably also need some new methods (server/moduleCreated / server/moduleDeleted?) to inform Haxe about changes based on file watcher events (similar to the server/invalidate we already have).

@Gama11 Gama11 added enhancement feature-ide IDE / Editor support labels Jun 20, 2019
@RealyUniqueName RealyUniqueName added this to the Backlog milestone Jun 20, 2019
@Simn
Copy link
Member

Simn commented Jun 29, 2019

This requires some design. Mostly because it's not even clear if a deleted/added file is even relevant with regards to class path resolution.

Actually, I don't think we'd need moduleDeleted because that should be the same as invalidate, right?

@Gama11
Copy link
Member Author

Gama11 commented Jun 29, 2019

Hm, right, I guess the compiler would notice that the file doesn't exist anymore when invalidating a deleted file...

@Simn
Copy link
Member

Simn commented Jun 29, 2019

I think the most straightforward way to implement moduleAdded is to invalidate all types (not just modules) that live in a module with the same name. It's a bit brute-force but I struggle to see how we would handle type resolution in the general case otherwise.

@djaonourside
Copy link

Guys, what's the issue status? I'm asking because suppose it's rather critical and basic aspect of editor language support.

@nadako
Copy link
Member

nadako commented Jul 28, 2019

Would be nice to have for 4.0 indeed, as it's pretty annoying when working in VS Code.

@Simn
Copy link
Member

Simn commented Aug 6, 2019

I'm willing to work on this, but I can't do much on the vshaxe side because it only compiles for @Gama11 these days.

I'll try to construct a failing test case for this

@Simn Simn self-assigned this Aug 6, 2019
Simn added a commit that referenced this issue Aug 6, 2019
Simn added a commit that referenced this issue Aug 6, 2019
* [tests] generalize server tests a bit

* [std] steal some types from vshaxe

* [tests] start on server display tests

see #8451

* remove CompilerMetadata type

* bring back methods

* add haxe.display.Server too

* utilize methods for tests
Simn added a commit that referenced this issue Aug 6, 2019
@Simn
Copy link
Member

Simn commented Aug 6, 2019

I have added server/moduleCreated and the test passes now. There's no additional invalidation going on yet, I'll have to check if that's the right thing to do. Now vshaxe needs an update.

@Simn
Copy link
Member

Simn commented Aug 8, 2019

@Gama11's observation is correct: If the module is created in an empty state and only "filled out" later, the type is not picked up. The following test sequence doesn't pass:

		vfs.putContent("Empty.hx", "");
		runHaxeJson([], ServerMethods.ModuleCreated, {file: new FsPath("Empty.hx")});
		vfs.putContent("Empty.hx", getTemplate("Empty.hx"));
		runHaxeJson([], ServerMethods.Invalidate, {file: new FsPath("Empty.hx")});
		runHaxeJson([], DisplayMethods.Completion, {file: new FsPath("HelloWorld.hx"), offset: 75, wasAutoTriggered: false});

Note that this problem is not specific to the new moduleCreated feature. I think we have mark files upon invalidation and then re-parse them on the next request that utilizes the syntax cache (unless they were already handled inbetween).

@Simn
Copy link
Member

Simn commented Aug 8, 2019

I have committed this approach. There's still an open debate I'm having with myself about whether or not the server/invalidate request is necessary for this to work. The issue is that without it, the compiler looks at the file again because it is never actually compiled.

The only way to handle that would be to check the modification time of all files in the syntax cache, which would likely be insanely slow.

@Simn
Copy link
Member

Simn commented Aug 9, 2019

I think we're done here.

@Simn Simn closed this as completed Aug 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement feature-ide IDE / Editor support
Projects
None yet
Development

No branches or pull requests

5 participants