Enhanced C#
Loyc library documentation
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Public fields | Public Member Functions | List of all members
Loyc.Syntax.LNodeRangeMapper Class Reference

Helps map locations (such as error locations) from a file (usually an output file) to an LNode (see Remarks). More...


Source file:

Remarks

Helps map locations (such as error locations) from a file (usually an output file) to an LNode (see Remarks).

A common scenario is that you've written code in Enhanced C# and then sent it through LeMP to produce an output file. The C# compiler produces error messages with locations in the output file, but you would like to see what part of the original Enhanced C# file is associated with those errors. The LeMP Visual Studio extension could use this class to help obtain this information.

This requires (1) keeping track of the relationship between the output file and the original list of LNodes that contain source locations, and (2) an algorithm to map error locations back to source nodes and locations. Feature (1) is provided by individual node printers and can be requested via ILNodePrinterOptions.SaveRange. This class provides Feature (2). In addition, locations provided by a compiler tend to be line/column pairs instead of indexes, so (3) an ILineToIndex implementation is needed to convert line/column pairs to indexes.

Mapping back to a source location is trickier than mapping back to a source node, mainly because transformations (such as those done by LeMP) can introduce synthetic nodes, duplicate nodes, and nodes from other files. The node that best matches the output location might be something that has no location in the current source file, or no location in any source file.

Public fields

BMultiMap< int, Pair< ILNode,
int > > 
_startLocations = new BMultiMap<int, Pair<ILNode, int>>(null!, null!)
 
BMultiMap< int, Pair< ILNode,
int > > 
_endLocations = new BMultiMap<int, Pair<ILNode, int>>(null!, null!)
 
int SavedRangeCount => _startLocations.Count
 Gets the number of ranges that were stored with SaveRange. More...
 

Public Member Functions

void SaveRange (ILNode node, IndexRange range, int depth=-1)
 Associates a node with a range. More...
 
IReadOnlyList< Pair< ILNode,
IndexRange > > 
FindRelatedNodes (IndexRange targetRange, int maxSearchResults)
 Gets a list of nodes close to the requested range, ordered by similarity so that the first item in the returned list is the best result. More...
 
Pair< ILNode, IndexRangeFindMostUsefulRelatedNode (IndexRange targetRange, ISourceFile sourceFile, int searchIntensity=10)
 Selects the "closest" node to the target range, under the constraint that, if possible, you want to find a node belonging to a particular file and with a valid (non-negative) StartIndex. If there are no good results, this method will return a poor result instead (e.g. a node from a different file). More...
 
IReadOnlyList< Pair< ILNode,
IndexRange > > 
FindRelatedNodesCore (IndexRange targetRange, int maxSearchResults, bool trim)
 

Member Function Documentation

Pair<ILNode, IndexRange> Loyc.Syntax.LNodeRangeMapper.FindMostUsefulRelatedNode ( IndexRange  targetRange,
ISourceFile  sourceFile,
int  searchIntensity = 10 
)
inline

Selects the "closest" node to the target range, under the constraint that, if possible, you want to find a node belonging to a particular file and with a valid (non-negative) StartIndex. If there are no good results, this method will return a poor result instead (e.g. a node from a different file).

Returns
The best node and its range in the file being searched (not sourceFile, but the file for which ranges were saved via SaveRange(ILNode, IndexRange).)
IReadOnlyList<Pair<ILNode, IndexRange> > Loyc.Syntax.LNodeRangeMapper.FindRelatedNodes ( IndexRange  targetRange,
int  maxSearchResults 
)

Gets a list of nodes close to the requested range, ordered by similarity so that the first item in the returned list is the best result.

Returns
A list of nodes and their ranges, sorted by similarity to the targetRange (most similar first), and limited in size as requested. The nodes and ranges must have been previously saved via SaveRange(ILNode, IndexRange).
void Loyc.Syntax.LNodeRangeMapper.SaveRange ( ILNode  node,
IndexRange  range,
int  depth = -1 
)
inline

Associates a node with a range.

Typically this method is set as the value of ILNodePrinterOptions.SaveRange so that range info is captured while converting a node to text. This class does not need or use the third parameter (depth).

Member Data Documentation

int Loyc.Syntax.LNodeRangeMapper.SavedRangeCount => _startLocations.Count

Gets the number of ranges that were stored with SaveRange.