D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
SyntaxSuggest
/
BlockExpand
/
Filename :
expand_neighbors-i.ri
back
Copy
U:RDoc::AnyMethod[iI"expand_neighbors:ETI"0SyntaxSuggest::BlockExpand#expand_neighbors;TF:publico:RDoc::Markup::Document:@parts[!o:RDoc::Markup::Paragraph; [I"DA neighbor is code that is at or above the current indent line.;To:RDoc::Markup::BlankLine o; ; [I"GFirst we build a block with all neighbors. If we can't go further ;TI"Kthen we decrease the indentation threshold and expand via indentation ;TI"i.e. `expand_indent`;T@o; ; [I"Handles two general cases.;T@o; ; [I":## Case #1: Check code inside of methods/classes/etc.;T@o; ; [I"\It's important to note, that not everything in a given indentation level can be parsed ;TI"@as valid code even if it's part of valid code. For example:;T@o:RDoc::Markup::Verbatim; [ I"1 hash = { ;TI"2 name: "richard", ;TI"3 dog: "cinco", ;TI" 4 } ;T:@format0o; ; [I"]In this case lines 2 and 3 will be neighbors, but they're invalid until `expand_indent` ;TI"is called on them.;T@o; ; [I"WWhen we are adding code within a method or class (at the same indentation level), ;TI"Kuse the empty lines to denote the programmer intended logical chunks. ;TI"*Stop and check each one. For example:;T@o;; [ I"1 def dog ;TI"2 print "dog" ;TI"3 ;TI"4 hash = { ;TI"5 end ;T; 0o; ; [I"[If we did not stop parsing at empty newlines then the block might mistakenly grab all ;TI"Ythe contents (lines 2, 3, and 4) and report them as being problems, instead of only ;TI"line 4.;T@o; ; [I"1## Case #2: Expand/grab other logical blocks;T@o; ; [ I"ZOnce the search algorithm has converted all lines into blocks at a given indentation ;TI"\it will then `expand_indent`. Once the blocks that generates are expanded as neighbors ;TI"Xwe then begin seeing neighbors being other logical blocks i.e. a block's neighbors ;TI"Cmay be another method or class (something with keywords/ends).;T@o; ; [I"For example:;T@o;; [I"1 def bark ;TI"2 ;TI"3 end ;TI"4 ;TI"5 def sit ;TI"6 end ;T; 0o; ; [I"XIn this case if lines 4, 5, and 6 are in a block when it tries to expand neighbors ;TI"\it will expand up. If it stops after line 2 or 3 it may cause problems since there's a ;TI"Avalid kw/end pair, but the block will be checked without it.;T@o; ; [I"NWe try to resolve this edge case with `lookahead_balance_one_line` below.;T: @fileI"'lib/syntax_suggest/block_expand.rb;T:0@omit_headings_from_table_of_contents_below000[ I"(block);T@UFI"BlockExpand;TcRDoc::NormalClass00