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

Gloabl constants reference search #1089

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

Conversation

lindhuber
Copy link

Replaced the xtext find reference search with the 4diac model search in the global constants editor. It currently does not match on the fully qualified name (e.g. "value2" instead of "GlobalTest::value2") as otherwise it would not match the occurrences in the ST code anymore.

The model search now has an option to search in the initial values of fb types. Searching global constants in fb instances is not possible as constants are converted to their value literals when instantiated.
@lindhuber lindhuber requested a review from oberlehner February 20, 2025 13:09
Copy link

Test Results

   113 files  ±0     113 suites  ±0   50s ⏱️ -1s
29 183 tests ±0  29 183 ✅ ±0  0 💤 ±0  0 ❌ ±0 
29 184 runs  ±0  29 184 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 49880cc. ± Comparison against base commit 5edc7a8.

import org.eclipse.xtext.ui.editor.findrefs.FindReferencesHandler;

@SuppressWarnings("restriction")
public class GlobalConstantsFindReferencesHandler extends FindReferencesHandler {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please give a more generic name. we might want to reuse that handler in other places too in the future.
Maybe FordiacFindReferencesHandler

Copy link
Member

Choose a reason for hiding this comment

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

I believe we need to use it also in the other ST languages to handle references to global constants from other ST sources. Please move it to the corresponding structuredtextcore.ui plugin. By the existing naming convention, it should then also be renamed to STCoreFindReferencesHandler.

@mx990 mx990 self-requested a review February 21, 2025 07:21
import org.eclipse.xtext.ui.editor.findrefs.FindReferencesHandler;

@SuppressWarnings("restriction")
public class GlobalConstantsFindReferencesHandler extends FindReferencesHandler {
Copy link
Member

Choose a reason for hiding this comment

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

I believe we need to use it also in the other ST languages to handle references to global constants from other ST sources. Please move it to the corresponding structuredtextcore.ui plugin. By the existing naming convention, it should then also be renamed to STCoreFindReferencesHandler.

@@ -206,7 +206,7 @@
</extension>
<extension point="org.eclipse.ui.handlers">
<handler
class="org.eclipse.fordiac.ide.globalconstantseditor.ui.GlobalConstantsExecutableExtensionFactory:org.eclipse.xtext.ui.editor.findrefs.FindReferencesHandler"
class="org.eclipse.fordiac.ide.globalconstantseditor.ui.GlobalConstantsExecutableExtensionFactory:org.eclipse.fordiac.ide.globalconstantseditor.ui.handlers.GlobalConstantsFindReferencesHandler"
Copy link
Member

Choose a reason for hiding this comment

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

Please change the handlers in the other ST languages, as well.


@Override
protected void findReferences(final EObject target) {
if (target instanceof final STVarDeclaration varDec) {
Copy link
Member

Choose a reason for hiding this comment

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

Please check that it is a global constant and not a local variable with the additional condition:

Suggested change
if (target instanceof final STVarDeclaration varDec) {
if (target instanceof final STVarDeclaration varDec && varDec.eContainer() instanceof STVarGlobalDeclarationBlock) {

@@ -27,7 +27,10 @@ Require-Bundle: org.eclipse.fordiac.ide.globalconstantseditor,
org.eclipse.fordiac.ide.typemanagement,
org.eclipse.fordiac.ide.systemmanagement,
org.eclipse.ui,
org.eclipse.ui.editors
org.eclipse.ui.editors,
org.eclipse.ui.navigator,
Copy link
Member

Choose a reason for hiding this comment

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

Do you actually need the navigator dependency?

if (modelElement instanceof final VarDeclaration varDecl) {
final var value = varDecl.getValue();
return value != null && !value.getValue().isEmpty()
&& value.getValue().contains(modelQuerySpec.searchString());
Copy link
Member

Choose a reason for hiding this comment

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

In order to accurately search for global constants in packages, I would suggest to first strip any leading packages for simple string pre-matching and then use the ST search to determine if it is actually a match.

@diplfranzhoepfinger
Copy link

WOW ! i would like this.

also it would be great to have a Function when i see a Constant, to jup to the Definition.

@oberlehner
Copy link
Contributor

I don't find refernces in interfaces of untyped subapps:
image

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