/// <summary> /// Creates a new CSharpIndentEngine instance from the given prototype. /// </summary> /// <param name="prototype"> /// An CSharpIndentEngine instance. /// </param> public CSharpIndentEngine(CSharpIndentEngine prototype) { this.options = prototype.options; this.newLineChar = prototype.newLineChar; this.currentState = prototype.currentState.Clone(this); this.conditionalSymbols = new HashSet <string>(prototype.conditionalSymbols); this.customConditionalSymbols = new HashSet <string>(prototype.customConditionalSymbols); this.wordToken = new StringBuilder(prototype.wordToken.ToString()); this.previousKeyword = string.Copy(prototype.previousKeyword); this.offset = prototype.offset; this.line = prototype.line; this.column = prototype.column; this.isLineStart = prototype.isLineStart; this.isLineStartBeforeWordToken = prototype.isLineStartBeforeWordToken; this.currentChar = prototype.currentChar; this.previousChar = prototype.previousChar; this.previousNewline = prototype.previousNewline; this.currentIndent = new StringBuilder(prototype.CurrentIndent.ToString()); this.lineBeganInsideMultiLineComment = prototype.lineBeganInsideMultiLineComment; this.lineBeganInsideVerbatimString = prototype.lineBeganInsideVerbatimString; this.ifDirectiveEvalResults = prototype.ifDirectiveEvalResults.Clone(); this.ifDirectiveIndents = prototype.ifDirectiveIndents.Clone(); this.EnableCustomIndentLevels = prototype.EnableCustomIndentLevels; }
async void HandleTextOptionsChanged(object sender, EventArgs e) { //var options = Editor.CreateNRefactoryTextEditorOptions (); var optionTask = DocumentContext?.AnalysisDocument?.GetOptionsAsync(); if (optionTask == null) { return; } optionSet = await optionTask; if (optionSet == null) { return; } //options.IndentBlankLines = true; ICSharpCode.NRefactory6.CSharp.IStateMachineIndentEngine indentEngine; try { var csharpIndentEngine = new ICSharpCode.NRefactory6.CSharp.CSharpIndentEngine(optionSet); //csharpIndentEngine.EnableCustomIndentLevels = true; foreach (var symbol in GetDefinedSymbols(DocumentContext.Project)) { csharpIndentEngine.DefineSymbol(symbol); } indentEngine = csharpIndentEngine; } catch (Exception ex) { LoggingService.LogError("Error while creating the c# indentation engine", ex); indentEngine = new ICSharpCode.NRefactory6.CSharp.NullIStateMachineIndentEngine(); } await Runtime.RunInMainThread(delegate { stateTracker = new ICSharpCode.NRefactory6.CSharp.CacheIndentEngine(indentEngine); if (DefaultSourceEditorOptions.Instance.IndentStyle == IndentStyle.Auto) { Editor.IndentationTracker = null; } else { Editor.IndentationTracker = new IndentVirtualSpaceManager(Editor, stateTracker); } indentationDisabled = DefaultSourceEditorOptions.Instance.IndentStyle == IndentStyle.Auto || DefaultSourceEditorOptions.Instance.IndentStyle == IndentStyle.None; if (indentationDisabled) { Editor.SetTextPasteHandler(null); } else { Editor.SetTextPasteHandler(new CSharpTextPasteHandler(this, stateTracker, optionSet)); } }); }
async void HandleTextOptionsChanged(object sender, EventArgs e) { optionSet = await DocumentContext.GetOptionsAsync(); IStateMachineIndentEngine indentEngine; try { var csharpIndentEngine = new ICSharpCode.NRefactory6.CSharp.CSharpIndentEngine(optionSet); //csharpIndentEngine.EnableCustomIndentLevels = true; foreach (var symbol in GetDefinedSymbols(DocumentContext.Project)) { csharpIndentEngine.DefineSymbol(symbol); } indentEngine = csharpIndentEngine; } catch (Exception ex) { LoggingService.LogError("Error while creating the c# indentation engine", ex); indentEngine = new ICSharpCode.NRefactory6.CSharp.NullIStateMachineIndentEngine(); } await Runtime.RunInMainThread(delegate { try { var editor = Editor; if (editor == null) // disposed { return; } stateTracker = new ICSharpCode.NRefactory6.CSharp.CacheIndentEngine(indentEngine); if (DefaultSourceEditorOptions.Instance.IndentStyle == IndentStyle.Auto) { editor.IndentationTracker = null; } else { editor.IndentationTracker = new CSharpIndentationTracker(editor, DocumentContext); } indentationDisabled = DefaultSourceEditorOptions.Instance.IndentStyle == IndentStyle.Auto || DefaultSourceEditorOptions.Instance.IndentStyle == IndentStyle.None; if (indentationDisabled) { editor.SetTextPasteHandler(null); } else { editor.SetTextPasteHandler(new CSharpTextPasteHandler(this, optionSet)); } } catch (Exception ex) { LoggingService.LogError("Error while handling text option change.", ex); } }); }
public static IDocumentIndentEngine CreateEngine(string text, OptionSet formatOptions = null, IEnumerable<string> symbols = null) { var policy = formatOptions; if (policy == null) { policy = FormattingOptionsFactory.CreateMono(); // policy.IndentPreprocessorDirectives = false; // policy.AlignToFirstMethodCallArgument = policy.AlignToFirstIndexerArgument = true; } var sb = new StringBuilder(); int offset = 0; for (int i = 0; i < text.Length; i++) { var ch = text[i]; if (ch == '$') { offset = i; continue; } sb.Append(ch); } var document = SourceText.From(sb.ToString()); var csi = new CSharpIndentEngine(policy) { EnableCustomIndentLevels = true }; if (symbols != null) { foreach (var sym in symbols) { csi.DefineSymbol(sym); } } var result = new CacheIndentEngine(csi); result.Update(document, offset); return result; }
/// <summary> /// Creates a new CSharpIndentEngine instance from the given prototype. /// </summary> /// <param name="prototype"> /// An CSharpIndentEngine instance. /// </param> public CSharpIndentEngine(CSharpIndentEngine prototype) { this.options = prototype.options; this.newLineChar = prototype.newLineChar; this.currentState = prototype.currentState.Clone(this); this.conditionalSymbols = new HashSet<string>(prototype.conditionalSymbols); this.customConditionalSymbols = new HashSet<string>(prototype.customConditionalSymbols); this.wordToken = new StringBuilder(prototype.wordToken.ToString()); this.previousKeyword = string.Copy(prototype.previousKeyword); this.offset = prototype.offset; this.line = prototype.line; this.column = prototype.column; this.isLineStart = prototype.isLineStart; this.isLineStartBeforeWordToken = prototype.isLineStartBeforeWordToken; this.currentChar = prototype.currentChar; this.previousChar = prototype.previousChar; this.previousNewline = prototype.previousNewline; this.currentIndent = new StringBuilder(prototype.CurrentIndent.ToString()); this.lineBeganInsideMultiLineComment = prototype.lineBeganInsideMultiLineComment; this.lineBeganInsideVerbatimString = prototype.lineBeganInsideVerbatimString; this.ifDirectiveEvalResults = prototype.ifDirectiveEvalResults.Clone(); this.ifDirectiveIndents = prototype.ifDirectiveIndents.Clone(); this.EnableCustomIndentLevels = prototype.EnableCustomIndentLevels; }
void HandleTextOptionsChanged (object sender, EventArgs e) { //var options = Editor.CreateNRefactoryTextEditorOptions (); optionSet = Policy.CreateOptions (Editor.Options); //options.IndentBlankLines = true; ICSharpCode.NRefactory6.CSharp.IStateMachineIndentEngine indentEngine; try { var csharpIndentEngine = new ICSharpCode.NRefactory6.CSharp.CSharpIndentEngine (optionSet); //csharpIndentEngine.EnableCustomIndentLevels = true; foreach (var symbol in GetDefinedSymbols (DocumentContext.Project)) { csharpIndentEngine.DefineSymbol (symbol); } indentEngine = csharpIndentEngine; } catch (Exception ex) { LoggingService.LogError ("Error while creating the c# indentation engine", ex); indentEngine = new ICSharpCode.NRefactory6.CSharp.NullIStateMachineIndentEngine (); } stateTracker = new ICSharpCode.NRefactory6.CSharp.CacheIndentEngine (indentEngine); if (DefaultSourceEditorOptions.Instance.IndentStyle == IndentStyle.Auto) { Editor.SetIndentationTracker (null); } else { Editor.SetIndentationTracker (new IndentVirtualSpaceManager (Editor, stateTracker)); } indentationDisabled = DefaultSourceEditorOptions.Instance.IndentStyle == IndentStyle.Auto || DefaultSourceEditorOptions.Instance.IndentStyle == IndentStyle.None; if (indentationDisabled) { Editor.SetTextPasteHandler (null); } else { Editor.SetTextPasteHandler (new CSharpTextPasteHandler (this, stateTracker, optionSet)); } }