/// <summary> /// Set scintilla to use the contained lexer /// </summary> public static void ActivateHighlight() { Sci.Lexer = Lexer.Container; Sci.SetProperty("fold", "1"); // Configure a margin to display folding symbols Sci.GetMargin(2).Type = MarginType.Symbol; Sci.GetMargin(2).Mask = Sci.Marker.MaskFolders; Sci.GetMargin(2).Sensitive = true; Sci.GetMargin(2).Width = 20; // Enable folding Sci.AutomaticFold = AutomaticFold.Show | AutomaticFold.Click | AutomaticFold.Change; _lineInfo.Clear(); Sci.Colorize(0, -1); }
/// <summary> /// Displays the errors for the current file (if any) /// display an annotation with the message below the line + display a marker in the margin /// </summary> public static void UpdateErrorsInScintilla() { // Updates the number of errors in the FileExplorer form and the file status UpdateFileStatus(); var currentFilePath = Npp.CurrentFileInfo.Path; var marginError = Sci.GetMargin(ErrorMarginNumber); // need to clear scintilla for this file? if (_sessionInfo.ContainsKey(currentFilePath) && _sessionInfo[currentFilePath].NeedToCleanScintilla) { ClearAnnotationsAndMarkers(); _sessionInfo[currentFilePath].NeedToCleanScintilla = false; } // check if current file is a progress and if we got info on it if (!Npp.CurrentFileInfo.IsProgress || !_sessionInfo.ContainsKey(currentFilePath) || _sessionInfo[currentFilePath].FileErrors == null || _sessionInfo[currentFilePath].FileErrors.Count == 0) { if (marginError.Width > 0) { marginError.Width = 1; marginError.Width = 0; } // reset annotation to default Sci.AnnotationVisible = Plug.AnnotationMode; return; } // activate annotation (if not already done) Plug.AnnotationMode = Annotation.Indented; // show margin if (marginError.Sensitive == false) { marginError.Sensitive = true; } if (marginError.Type != MarginType.Symbol) { marginError.Type = MarginType.Symbol; } if (marginError.Mask != EveryMarkersMask) { marginError.Mask = EveryMarkersMask; } // only show the new errors if (_sessionInfo[currentFilePath].HasErrorsNotDisplayed) { _sessionInfo[currentFilePath].HasErrorsNotDisplayed = false; StylerHelper stylerHelper = new StylerHelper(); int lastLine = -2; StringBuilder lastMessage = new StringBuilder(); foreach (var fileError in _sessionInfo[currentFilePath].FileErrors) { // new line if (lastLine != fileError.Line) { stylerHelper.Clear(); lastMessage.Clear(); // set marker style now (the first error encountered for a given line is the highest anyway) if (!((int)Sci.GetLine(fileError.Line).MarkerGet()).IsBitSet((int)fileError.Level)) { Sci.GetLine(fileError.Line).MarkerAdd((int)fileError.Level); } } else { // append to existing annotation stylerHelper.Style("\n", (byte)fileError.Level); lastMessage.Append("\n"); } lastLine = fileError.Line; var mess = fileError.FromProlint ? "Prolint (level " + fileError.ErrorNumber : ("Compilation " + (fileError.Level == ErrorLevel.Critical ? "error" : "warning") + " (n°" + fileError.ErrorNumber); mess += fileError.FromProlint ? "): " : ", col " + fileError.Column + "): "; stylerHelper.Style(mess, (byte)(ScintillaTheme.ErrorAnnotBoldStyleOffset + fileError.Level)); lastMessage.Append(mess); mess = fileError.Message.BreakText(140); stylerHelper.Style(mess, (byte)(ScintillaTheme.ErrorAnnotStandardStyleOffset + fileError.Level)); lastMessage.Append(mess); if (Config.Instance.GlobalShowDetailedHelpForErrors && !string.IsNullOrEmpty(fileError.Help)) { mess = "\nDetailed help: " + fileError.Help.BreakText(140); stylerHelper.Style(mess, (byte)(ScintillaTheme.ErrorAnnotItalicStyleOffset + fileError.Level)); lastMessage.Append(mess); } if (fileError.Times > 0) { mess = "\nThis message above appeared " + fileError.Times + " times in the compiler log"; stylerHelper.Style(mess, (byte)(ScintillaTheme.ErrorAnnotBoldStyleOffset + fileError.Level)); lastMessage.Append(mess); } // set annotation Sci.GetLine(lastLine).AnnotationText = lastMessage.ToString(); Sci.GetLine(lastLine).AnnotationStyles = stylerHelper.GetStyleArray(); } } marginError.Width = ErrorMarginWidth + 1; marginError.Width = ErrorMarginWidth; }