atom / language-ruby

Ruby package for Atom
Other
101 stars 144 forks source link

Regex causes Gray (discolored) for large portion of Beginning #286

Closed jeff-hykin closed 3 years ago

jeff-hykin commented 4 years ago

Prerequisites

Description

The discoloration has some pretty strange behavior, it seems like a rendering problem instead of a parsing problem. It's a pretty big bug but I couldn't find a pre-existing issue for it.

Top of file is discolored, but (see next) Screen Shot 2020-06-22 at 2 48 53 PM

coloration is resumed a bit further down. Screen Shot 2020-06-22 at 2 48 47 PM

Steps to Reproduce

  1. atom --safe
  2. Select language Ruby
  3. Paste the following code
    
    require 'atk_toolbox'
    require 'nokogiri'
    require 'open-uri'
    require 'statistics2' 

this gets its value from the info.yaml file

$info = Info.new # load the info.yaml

$paths = $info.paths path_to_urls = $paths['all_urls'] PARAMETERS = $info['parameters']

def force_explicit_pathing(path) if FS.absolute_path?(path) File.join("/",path) else File.join("./",path) end end

def relative_path(from:nil, to:nil) Pathname.new(to).relative_path_from(Pathname.new(from)) end

def get_video_ids_for(url) return Hash[ Nokogiri::HTML.parse(open(url).read).css('*').map{ |each| each['href'] =~ /^\/watch\?v=([^\&]+)/ && $1 }.compact.collect{ |item| [item, {}] } ] end

def get_full_url(video_id) "https://www.youtube.com/watch?v=" + video_id end

def get_metadata_for(url) result = youtube-dl -j '#{url}' 2>&1 known_errors = [ "ERROR: This video has been removed for violating YouTube's Community Guidelines", "ERROR: This live stream recording is not available", "ERROR: This video is unavailable", ] if result =~ /#{known_errors.join("|")}/ return { unavailable: true, } end all_data = JSON.load(result) return {

title: all_data["title"],

    # description: all_data["description"],
    # categories: all_data["categories"],
    # tags: all_data["tags"],
    # subtitles: all_data["subtitles"],
    # automatic_captions: all_data["automatic_captions"],
    # view_count: all_data["view_count"],
    duration: all_data["duration"],
    fps: all_data["fps"],
    height: all_data["height"],
    width: all_data["width"],
}

end

class Numeric def percent return self/100.0 end end

def confidence_interval(total_num_of_trys, num_of_successes, confidence:0.95) return 0 if total_num_of_trys == 0

p_hat                     = 1.0*num_of_successes / total_num_of_trys
# num_of_negative_events    = total_num_of_trys - num_of_successes
# positive_deviation        = num_of_successes * ((1 - p_hat) ** 2)
# negative_deviation        = num_of_negative_events * ((0 - p_hat) ** 2)
# variance                  = (positive_deviation + negative_deviation) / (total_num_of_trys - 1)
# sample_standard_deviation = Math.sqrt(variance)
# estimated_stdev           = sample_standard_deviation / Math.sqrt(total_num_of_trys)
allowable_error           = 1 - confidence
allowable_error_per_side  = allowable_error / 2
one_sided_confidence      = 1 - allowable_error_per_side

z                   = Statistics2.pnormaldist(one_sided_confidence)
z_squared_per_event = z*z / total_num_of_trys
main_p_hat          = p_hat             + z_squared_per_event/2
inverse_p_hat       = p_hat*(1-p_hat)   + z_squared_per_event/4

top_part    = main_p_hat - z * Math.sqrt(inverse_p_hat/total_num_of_trys)
bottom_part = 1 + z_squared_per_event
lower_bound = top_part / bottom_part
difference  = p_hat - lower_bound
upper_bound = difference + p_hat
return [lower_bound, upper_bound]

end


### Versions

language-ruby: 0.72.23 Atom : 1.48.0 Electron: 5.0.13 Chrome : 73.0.3683.121 Node : 12.0.0



### Additional Information

1. Adding a space to the end of a line (or otherwise editing it) updates it.
![Screen Shot 2020-06-22 at 2 49 01 PM](https://user-images.githubusercontent.com/17692058/85329842-e5b38e80-b498-11ea-862f-36f31154ead4.png)

2. Reloading the window does sometimes resolves the issue. Could be possible the problem is beyond the language-ruby package.

3. This issue doesn't occur when switching the syntax from "Ruby" to "Ruby on Rails"
SampsonCrowley commented 4 years ago

Same problem with the exact same versions of Atom, Electron, Chrome, and Node (Arch Linux x64)

With language-ruby Screenshot from 2020-07-01 10-56-20

With ruby on rails Screenshot from 2020-07-01 10-57-30

ngelx commented 4 years ago

Same here

ozydingo commented 4 years ago

I've narrowed this down to regex parsing in my case.

With a dummy variable assigned as a string, we've got no problem:

Screen Shot 2020-09-24 at 6 10 05 AM

Add a regex with a special character class and that line goes white:

Screen Shot 2020-09-24 at 6 13 00 AM

Save, close, and reopen, and the whole file is white:

Screen Shot 2020-09-24 at 6 13 05 AM

Same issue does not occur with a simpler regex (plain d character instead of \d char class)

Screen Shot 2020-09-24 at 6 13 17 AM

Or with a regular character after the \d:

Screen Shot 2020-09-24 at 6 15 52 AM
ozydingo commented 4 years ago

Seems like my observations may be consistent with the use of \$ above.

ozydingo commented 4 years ago

Interpolation also appears to affect this, as in the /#{known_errors.join("|")}/ in OP's example

Screen Shot 2020-09-24 at 6 17 31 AM
ozydingo commented 4 years ago

Text in my example for ease of copy-paste:

  def message(service, event)
    test = /\d/
    text = ":goodnews: *Service Inquiry Status Update*\n" \
      "Media File: <#{media_file_url(service.media_file)}|#{service.media_file&.display_name}>\n" \
      "#{service.type} <#{service_url(service)}|#{service.id}>\n" \
      "Event: #{event}"
    return prod? ? text : dev_tag + text
  end
ozydingo commented 4 years ago

And I can confirm that the minimal example

def foo
  /\d/
end
Screen Shot 2020-09-24 at 6 24 39 AM

or even just

/\d/
Screen Shot 2020-09-24 at 6 25 29 AM

triggers the issue.

ozydingo commented 4 years ago

@jeff-hykin would it be appropriate to edit the title of this issue to something like "regex literals with some special characters break syntax highlighting" to get some more focused eyes on this issue?

jeff-hykin commented 4 years ago

Thanks for actually making progress on this @ozydingo I think I've seen an issue posted on Atom/Atom that describes this problem for multiple languages, so this should maybe be closed in favor of that one. However I can't seem to find that issue now.

ozydingo commented 4 years ago

@jeff-hykin yup, here it is!

ozydingo commented 4 years ago

It's probably the same issue, but I pause to close this since the syntax highlighting is not broken using language-ruby-on-rails, only language-ruby. If it's core to atom, I'm not sure why we would see that difference, but I could imagine up some scenarios sure. Still, I'd personally vote to leave this issue open given the slight possibility that this is in fact a language-ruby-specific issue.

Aerijo commented 4 years ago

It is a Tree-sitter bug; language-ruby-on-rails is a TextMate grammar.

I don't know if it's the same root cause, but Tree-sitter is known to have broken highlighting for a few languages.

darangi commented 3 years ago

This issue has been resolved here

You can get this fix in atom nightly before it gets to atom stable