Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

inline if statement has an 'end' statement linked to it and highlighted making the end statements after it incorrect #656

Description

@JarrColl

Your environment

  • vscode-ruby version: 0.27.0
  • Ruby version: N/A
  • Ruby version manager (if any): N/A
  • VS Code version: 1.44.2
  • Operating System: Windows
  • Using language server? (eg useLanguageServer is true in your configuration?) not using language server

Expected behavior

inline if statement isn't highlighted and linked to an end statement

Actual behavior

image

Here is the code sample:

def openPlayer(albums)
  id = read_integer_in_range("Enter album ID: ", 1, albums.length()) #Album ID selected
  system("clear") || system("cls")
  album = albums[id-1]

  album.tracks.each {|track| puts track.name}
  response = nil
  while(true)
    response = read_string("\nPlay Album? (y/n)") # Play album?
    if(response == 'y')
      playerGUI = MusicPlayerMain.new(album)
      playerGUI.show if __FILE__ == $0 # Open the player GUI
      break
    elsif(response == 'n')
      break
    else
      puts("Invalid Input")
    end
  end
end

Activity

  1. matt-stanley commented on Sep 29, 2020

    @matt-stanley

    Consider this workaround: use a semicolon (;) to end lines containing inline if statements. That will cause the block highlighting regex to ignore.

    I can't figure out a way to exclude inline if in the regex, but am willing to brainstorm if you have any ideas.

  2. graceful-potato commented on Oct 11, 2020

    @graceful-potato
    Contributor

    I can't figure out a way to exclude inline if in the regex, but am willing to brainstorm if you have any ideas.

    @matt-stanley could you please show a code that is responsible for this?

  3. matt-stanley commented on Oct 14, 2020

    @matt-stanley
  4. graceful-potato commented on Oct 14, 2020

    @graceful-potato
    Contributor

    I am not very familiar with vscode api, but is it possible to get textmate scope name from there? Recently I created PR where each language structure which closes with end keyword has different scope name. with it you can distinguish if modifier from if code block and optional do (like in while true do) from real do bloock
    #666

  5. graceful-potato commented on Oct 25, 2020

    @graceful-potato
    Contributor

    In short, this is not the only bug with this feature. It will break if you have a keyword in string, regular expression or even in comment section. And ofcourse it will break not only wtih if modifier, but also with unless while and until modifiers.
    Furthermore there are some ambigious cases with modifiers. For example
    "hello".match /(he)/ if condition and 10 / if rand(0..10) >= 5 then 5 else 2 end
    In both cases if goes after / but it is modifier only when it goes after regex. Same thing with %r<re> literal
    I am sure its possible to check for all this stuff with just a sequential matching with regexes but it will be quite hard. Strings, regexes and other structures could be multiline and you need to keep track of it while scanning in order to find a correct pair.

    Everything I mentioned before has already been solved in #666 . Unfortunately there is no API (microsoft/vscode#580) to get textmate scopes from extensions. So what I did is just parsed file again with new grammar file within this extension and it works fine. I think i fixed all bugs with this feature and now it can correctly highlight start and end of code blocks even in tricky oneliners like this:

    Screenshot from 2020-10-25 18-45-03
    Screenshot from 2020-10-25 18-45-23
    Screenshot from 2020-10-25 18-45-43
    Screenshot from 2020-10-25 18-45-55

    #670 if anyone wants to test

  6. github-actions commented on Nov 25, 2020

    @github-actions

    This issue has not had activity for 30 days. It will be automatically closed in 7 days.

  7. art-solopov commented on Sep 25, 2021

    @art-solopov

    I've just encountered this error a couple days ago. I know it's probably a bit anal-retentive on me, but this kind of issue makes me want to not use VS Code for Ruby development altogether. Are there any plans to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions