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

No information provided when set is fixed to certain element #3

Closed
kuhnt opened this issue Sep 29, 2023 · 3 comments
Closed

No information provided when set is fixed to certain element #3

kuhnt opened this issue Sep 29, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@kuhnt
Copy link
Contributor

kuhnt commented Sep 29, 2023

When I specify an element name in quotes to cause GAMS to operate over just a single element of a set (e.g. "noTill" in "c_p_t_i(curCrops,plot,"noTill","normal"), gams-ide does not provide me any information on this set.

However, often it would be helpful to 1) get the name of the set and 2) get the same information as clicking on the set.

@chrispahm
Copy link
Owner

Made a suggestion in #4, you can download the extension (VSIX) including the suggested changes here:
https://github.com/chrispahm/gams-ide/files/12776899/gams-ide-0.0.5.vsix.zip

image

Clicking on a quoted element will now show the expected set at the argument position of the enclosing parameter/variable/equation/set in the sidebar.

The picture shows this for the quoted element "67kW": It is the 2nd domain argument of the op_attr parameter. Upon clicking on "67kW", gams-ide performs the following steps

  1. Check if "67kW" is a known GAMS symbol → false (more on that later)
  2. Check if "67kW" is a quoted string → true
  3. Parse the source code line to find all GAMS symbols that look like this symbol(domain1,...,domainN) using PEG.js
  4. Find the encapsulating GAMS symbol corresponding to the clicked range (op_attr in the example), check it's domain (operation,machVar,rounded_plotSize,opAttr), and return the set found at the index position of the clicked symbol (cursor is on 2nd domain position) → which is the set machVar

Known issues

  1. Parsing currently fails if there is a whitespace before or after the "," separating the domains
  2. In a (rare) scenario where multiple sets contain an element with the same name, and a parameter is referencing these sets, it may occur that the plugin shows the wrong set for the index position.
    E.g consider the sets set a / test/; and set b /test/;, and a parameter defined as p_test(a,b);. If the parameter is called in the source code using p_test("test","test);, clicking on the second instance of "test" will result in the set a being shown in the sidebar, instead of the correct set b.

This happens because PEG.js outputs the same start and end locations for every domain encountered within a symbol, e.g.

{
    type: "functionCall",
    name: "c_p_t_i",
    args: [
      {
        name: "curCrops",
        location: {
          start: { offset: 8, line: 1, column: 9 },
          end: { offset: 39, line: 1, column: 40 },
        },
      },
      {
        name: "plot",
        location: {
          start: { offset: 8, line: 1, column: 9 },
          end: { offset: 39, line: 1, column: 40 },
        },
      },

To find the index of the domain that was clicked upon, we currently check if the word that was clicked upon is included the domains "name" property, and also if the start and end positions match with the current cursor position.
In order to solve this issue, the parser would need to be improved to ideally show the correct line for the specific elements and not the whole range.

@chrispahm
Copy link
Owner

Alright, I updated the parser which should fix the issues mentioned above!
Please try the attached new beta, which also includes a simple hint if a quoted element is clicked so it's easier to see if the package actually finds the correct set for the given position:
image

gams-ide-0.0.51.vsix.zip

@chrispahm chrispahm added the enhancement New feature or request label Oct 4, 2023
@chrispahm
Copy link
Owner

fixed by #4

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

No branches or pull requests

2 participants