Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Code Action Resource access(Trying to use the resource to filter possible executable commands)
Code Action Resource access [message #1869756] Fri, 23 August 2024 14:48 Go to next message
Ewen A Maclean is currently offline Ewen A MacleanFriend
Messages: 3
Registered: February 2017
Junior Member
Hello,

I have an implementation which exploits the xtext ICodeActionService2 implementation. From the Options (org.eclipse.xtext.ide.server.codeActions.ICodeActionService2.Options) I should be able to access both document and resource and allow querying the model to determine if an executeable command should be applicable:

```
val offset = document.getOffSet(position)
val element = resource.resolveContainedElementAt(offset)
```
pre 2.20 the codeActions Options were populate with the resource - e.g.:

https://github.com/eclipse/xtext/blob/fedf312fcc8f88605fdf182e3ae2041de793ce4a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/LanguageServerImpl.java#L785

but now this is the not the case:

https://github.com/eclipse/xtext/blob/main/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/LanguageServerImpl.java#L818-L823

so the resource is always null.

I was wondering if there was a way to access the resource from somewhere else in the IDE module - I have available a ProjectManager via the ServerModule, but not entirely sure how to initialise this properly

many thanks for any help
Re: Code Action Resource access [message #1869762 is a reply to message #1869756] Fri, 23 August 2024 17:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
Maybe you can do some archeology on
https://github.com/eclipse/xtext/commit/955533e89e829c3ca0e182a4e47eec3db5727bcc#diff-de69d0b3cc6ee48a1c1dd195a62c2109a69addda2bc3d5729fd58889bf6344e3

https://github.com/eclipse/xtext-core/pull/1915

And why the set resource is not called.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com

[Updated on: Fri, 23 August 2024 17:58]

Report message to a moderator

Re: Code Action Resource access [message #1869765 is a reply to message #1869762] Fri, 23 August 2024 18:19 Go to previous messageGo to next message
Ewen A Maclean is currently offline Ewen A MacleanFriend
Messages: 3
Registered: February 2017
Junior Member
thank you! Will study this
Re: Code Action Resource access [message #1870407 is a reply to message #1869765] Mon, 26 August 2024 11:05 Go to previous messageGo to next message
Ewen A Maclean is currently offline Ewen A MacleanFriend
Messages: 3
Registered: February 2017
Junior Member
Thanks a lot for the links here - the correct way now to do this (for reference in case someone else find this) is to use e.g.

```
options.languageServerAccess.doSyncRead(options.URI, [ Context context |
val resource = context.resource
val document = context.document
....
)
```
Re: Code Action Resource access [message #1870410 is a reply to message #1870407] Mon, 26 August 2024 11:51 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
yes this is what i assume.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Previous Topic:Xtext 2.36.0 is out
Next Topic:[LSP]: How to support project configuration files
Goto Forum:
  


Current Time: Wed Jan 15 13:46:51 GMT 2025

Powered by FUDForum. Page generated in 0.04464 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top