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

Modifying a spec file with a partial entry throws python exception and pops up an error box in Visual Studio Code #42

Open
sreeves opened this issue Nov 13, 2023 · 1 comment

Comments

@sreeves
Copy link

sreeves commented Nov 13, 2023

Fresh git clone and build/install today. Ran VSCode pointing at podman package checkout from SUSE:SLE-15-SP5:Update.
Started to modify the spec file and only added a "{_datadir}" entry on a new line and hovering over that pops up a "Request textDocument/hover failed" message box and the command line shows the following python exception

ERROR:_handle_request:Failed to handle request 29 textDocument/hover HoverParams(text_document=TextDocumentIdentifier(uri='file:///home/vmuser1/obs_internal/podman/podman.spec'), position=63:6, work_done_token=None)
Traceback (most recent call last):
  File "/home/vmuser1/.cache/pypoetry/virtualenvs/rpm-spec-language-server-Ve3TtjRo-py3.11/lib/python3.11/site-packages/pygls/protocol/json_rpc.py", line 265, in _handle_request
    self._execute_request(msg_id, handler, params)
  File "/home/vmuser1/.cache/pypoetry/virtualenvs/rpm-spec-language-server-Ve3TtjRo-py3.11/lib/python3.11/site-packages/pygls/protocol/json_rpc.py", line 187, in _execute_request
    self._send_response(msg_id, handler(params))
                                ^^^^^^^^^^^^^^^
  File "/home/vmuser1/git_repo/rpm-spec-language-server/rpm_spec_language_server/server.py", line 400, in expand_macro
    macro = get_macro_under_cursor(
            ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vmuser1/git_repo/rpm-spec-language-server/rpm_spec_language_server/macros.py", line 103, in get_macro_under_cursor
    symbol = get_macro_string_at_position(lines[position.line], position.character)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vmuser1/git_repo/rpm-spec-language-server/rpm_spec_language_server/macros.py", line 19, in get_macro_string_at_position
    line[i] == "%"
    ~~~~^^^
IndexError: string index out of range
@dcermak
Copy link
Owner

dcermak commented Nov 15, 2023

Ok, this is a nasty issue. What happens under the hood is the following: you added %_datadir below the preamble section. But that renders the spec file invalid, which results in the LSP server having a stale internal spec state (as rpm fails to parse the spec now). Thereby it keeps looking for the macro on the correct line, but in its internal state, that line is empty.

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

No branches or pull requests

2 participants