public override int ColorizeLine(int line, int length, IntPtr ptr, int state, uint[] attrs) { NemerleScanner scanner = (NemerleScanner)Scanner; scanner._currentLine = line; ScanLexer lex = scanner.GetLexer(); if (lex == null) { return(0); } lex.SetFileName(scanner._source.GetFilePath()); int ret; try { ret = base.ColorizeLine(line, length, ptr, state, attrs); if (attrs != null && scanner._colorizeEnd) { attrs[length] = (uint)scanner._lastColor; } } finally { scanner._currentLine = -1; } return(ret); }
public void SetHighlights(IIdeSource source, IEnumerable <GotoInfo> highlights) { var isPermanent = false; var nsource = source as NemerleSource; if (nsource == null) { return; } ScanLexer lexer = nsource.Scanner.GetLexer(); if (lexer == null) { return; } if (isPermanent) { lexer.AddHighlighting(highlights); } else { lexer.SetHoverHighlights(highlights); } nsource.Recolorize(1, source.LineCount); }
public void SetSource(string source, int offset) { //System.Diagnostics.Debug.WriteLine(string.Format("Scan line {0}", _currentLine)); ScanLexer lexer = GetLexer(); if (lexer != null) { if (_currentLine >= 0 && source.Length > 0) { if (_source != null && _source.ProjectInfo != null) { var ret = _source.ProjectInfo.Engine.GetActiveEnv(_source.FileIndex, _currentLine + 1); if (ret.Field0 != null) { _env = ret.Field0; _type = ret.Field1; } } } lexer.SetLine(_currentLine + 1, source, offset, _env, _type); } }
internal ScanLexer GetLexer() { if (_lexer == null) { _lexer = GetNewLexer(); } return(_lexer); }
public BracketFinder(NemerleSource source, int startLine, int startCol, NemerleScanner scanner, IVsTextColorState colorState) { #region Init fields Scanner = scanner; Source = source; StartLine = startLine; Lex = scanner.GetNewLexer(); Lex.SetFileName(source.GetFilePath()); ColorState = colorState; _lineCount = source.GetLineCount(); var line = startLine - 1; _buffer = new string[1] { source.GetText(line, 0, line, source.GetLineLength(line)) }; _startBufferLine = line; #endregion #region 2. Determine that it is a paired token. 3. Determine paired token. // Get tokens of line under text carret into dynamic array. List <ScanTokenInfo> lineToks = GetLineTokens(startLine, true); // Find index of token which located under text carret. int index = FindIndex(lineToks, x => x.Token.Location.Contains(startLine, startCol)); if (index < 0) { return; } // If index is corret get corresponding token. ScanTokenInfo startBraceInfo = lineToks[index]; // Remember it, if token have paired token. if (IsPairedToken(startBraceInfo.Token)) { StartBraceInfo = startBraceInfo; } else { // otherwise try get right-hand token... startBraceInfo = RightHand(lineToks, index); // Remember it, if token have paired token. if (IsPairedToken(startBraceInfo.Token)) { StartBraceInfo = startBraceInfo; } } #endregion }
/// <summary> /// Implementation of<c>GetLineTokens</c>(). Don't use this method directly! /// </summary> IEnumerable <ScanTokenInfo> GetLineTokens(ScanLexer lex, ScanState scanState) { ScanTokenInfo info = lex.GetToken(scanState); scanState = info.State; while (!info.IsEndOfLine) { yield return(info); info = lex.GetToken(scanState); scanState = info.State; } }
internal void RemoveLastHighlighting(IIdeSource source) { Debug.WriteLine(">>>> ##### RemoveLastHighlighting!"); var nsource = source as NemerleSource; if (nsource == null) { return; } ScanLexer lexer = nsource.Scanner.GetLexer(); if (lexer == null) { return; } lexer.RemoveLastHighlighting(); nsource.Recolorize(1, source.LineCount); Debug.WriteLine("<<<< ##### HighlightUsages!"); }
internal ScanLexer GetLexer() { if (_lexer == null) _lexer = GetNewLexer(); return _lexer; }