Closed AndreasArvidsson closed 2 years ago
This approach seems reasonable, the only slight annoyance being that getNodeAtLocation
would have to become async, because it might need to load the wasm, which is async. This async-ness then becomes contagious, so eg in cursorless, transformSelection
becomes async as well, and then everything up the chain from there 😕. Not sure I see a better alternative tho. Any ideas?
I have no better solution. If you really want to keep it synchronous I guess you could always do a busy wait via a loop.
In #5, I opted to just raise a special exception (LanguageStillLoadingError
) for this case. Client code can catch the exception and try again. If desired, I could add a separate version of the function that is async, but I think I'd prefer to keep the default implementation sync and just throw an exception
The tree map is dependent on the events
onDidChangeVisibleTextEditors
andonDidChangeTextDocument
to add new languages when needed.Quickly changing language on a file or switching to a file with a different language and immediately calling
getNodeAtLocation
throws an exception "Can't read property rootNode of undefined".One solution would be that in getNodeAtLocation do the following:
Language {lang} is not supported by the tree parser
Similar thoughts might be applied to the function
getTree