internal static FormattingOptions CreateFormattingOptions(IEditorOptions editorOptions, ITextSnapshot snapshot) { FormattingOptions res = new FormattingOptions(); if (editorOptions.IsConvertTabsToSpacesEnabled()) { res.SpacesPerIndent = editorOptions.GetIndentSize(); } else { res.SpacesPerIndent = null; } res.NewLine = VsExtensions.GetNewLineText(snapshot); res.SpaceAfterComma = NodejsPackage.Instance.FormattingSpacingOptionsPage.SpaceAfterComma; res.SpaceAfterSemiColonInFor = NodejsPackage.Instance.FormattingSpacingOptionsPage.SpaceAfterSemicolonInFor; res.SpaceBeforeAndAfterBinaryOperator = NodejsPackage.Instance.FormattingSpacingOptionsPage.SpaceBeforeAndAfterBinaryOperator; res.SpaceAfterKeywordsInControlFlowStatements = NodejsPackage.Instance.FormattingSpacingOptionsPage.SpaceAfterKeywordsInControlFlow; res.SpaceAfterFunctionInAnonymousFunctions = NodejsPackage.Instance.FormattingSpacingOptionsPage.SpaceAfterFunctionKeywordForAnonymousFunctions; res.SpaceAfterOpeningAndBeforeClosingNonEmptyParenthesis = NodejsPackage.Instance.FormattingSpacingOptionsPage.SpaceAfterOpeningAndBeforeClosingNonEmptyParens; res.OpenBracesOnNewLineForFunctions = NodejsPackage.Instance.FormattingBracesOptionsPage.BraceOnNewLineForFunctions; res.OpenBracesOnNewLineForControl = NodejsPackage.Instance.FormattingBracesOptionsPage.BraceOnNewLineForControlBlocks; return(res); }
public void OnReturn(IBraceCompletionSession session) { if (NodejsPackage.Instance.FormattingGeneralOptionsPage.FormatOnEnter) { // reshape code from // { // |} // // to // { // | // } // where | indicates caret position. var closingPointPosition = session.ClosingPoint.GetPosition(session.SubjectBuffer.CurrentSnapshot); Debug.Assert( condition: closingPointPosition > 0, message: "The closing point position should always be greater than zero", detailMessage: "The closing point position should always be greater than zero, " + "since there is also an opening point for this brace completion session"); // Insert an extra newline and indent the closing brace manually. session.SubjectBuffer.Insert( closingPointPosition - 1, VsExtensions.GetNewLineText(session.TextView.TextSnapshot)); // Format before setting the caret. Format(session); // After editing, set caret to the correct position. SetCaretPosition(session); } }
protected override void DoOpenFileCommand() { if (SelectedNode is ITestFileModel file) { VsExtensions.OpenProjectItem(file.Path); } }
protected override void DoOpenFileCommand() { if (SelectedNode is SourcefileViewModel file) { VsExtensions.OpenProjectItem(file.FileName); } }
public void Invoke(CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { return; } VsExtensions.SaveProjectItem(_filePath); _tests.RunTests(_filePath, _lineNumber); }
internal static IEnumerable <TestProject> GetTests() { foreach (Project vsProject in VsExtensions.GetProjects()) { TestProject project = CreateProject(vsProject); if (project != null) { yield return(project); } } }
protected override void DoLoadCommand() { if (VsExtensions.IsFolder()) { DTE dte = (DTE)Package.GetGlobalService(typeof(DTE)); LoadFromFolder(dte.Solution.FileName); } else { LoadFromSolution(); } if (Model.Projects.Count == 0) { base.DoLoadCommand(); } }
public override List <string> GetScriptFileNames() { if (VsExtensions.IsFolder()) { return(base.GetScriptFileNames()); } List <string> fileNames = new List <string>(); foreach (Project vsProject in VsExtensions.GetProjects()) { GetScriptFileNames(vsProject.ProjectItems, fileNames); } if (fileNames.Count == 0) { return(base.GetScriptFileNames()); } return(fileNames); }
public int FormatSpan(IVsTextLines pBuffer, TextSpan[] ts) { IXMLDOMNode codeNode, snippetTypes, declarations; int hr; if (ErrorHandler.Failed(hr = _session.GetSnippetNode("CodeSnippet:Code", out codeNode))) { return(hr); } if (ErrorHandler.Failed(hr = _session.GetHeaderNode("CodeSnippet:SnippetTypes", out snippetTypes))) { return(hr); } List <string> declList = new List <string>(); if (ErrorHandler.Succeeded(hr = _session.GetSnippetNode("CodeSnippet:Declarations", out declarations)) && declarations != null) { foreach (IXMLDOMNode declType in declarations.childNodes) { var id = declType.selectSingleNode("./CodeSnippet:ID"); if (id != null) { declList.Add(id.text); } } } bool surroundsWith = false; foreach (MSXML.IXMLDOMNode snippetType in snippetTypes.childNodes) { if (snippetType.nodeName == "SnippetType") { if (snippetType.text == SurroundsWith) { surroundsWith = true; } } } // get the indentation of where we're inserting the code... string baseIndentation = GetBaseIndentation(ts); using (var edit = _textView.TextBuffer.CreateEdit()) { if (surroundsWith) { var templateText = codeNode.text.Replace("\r\n", VsExtensions.GetNewLineText(_textView.TextSnapshot)); foreach (var decl in declList) { string defaultValue; if (ErrorHandler.Succeeded(_session.GetFieldValue(decl, out defaultValue))) { templateText = templateText.Replace("$" + decl + "$", defaultValue); } } templateText = templateText.Replace("$end$", ""); // we can finally figure out where the selected text began witin the original template... int selectedIndex = templateText.IndexOf("$selected$"); if (selectedIndex != -1) { var selection = _textView.Selection; // now we need to get the indentation of the $selected$ element within the template, // as we'll need to indent the selected code to that level. string indentation = GetTemplateSelectionIndentation(templateText, selectedIndex); var start = _selectionStart.GetPosition(_textView.TextBuffer.CurrentSnapshot); var end = _selectionEnd.GetPosition(_textView.TextBuffer.CurrentSnapshot); if (end < start) { // we didn't actually have a selection, and our negative tracking pushed us // back to the start of the buffer... end = start; } var selectedSpan = Span.FromBounds(start, end); if (surroundsWith) { if (string.IsNullOrWhiteSpace(_textView.TextBuffer.CurrentSnapshot.GetText(selectedSpan))) { // Surround With can be invoked with no selection, but on a line with some text. // In that case we need to inject an extra new line. var endLine = _textView.TextBuffer.CurrentSnapshot.GetLineFromPosition(end); var endText = endLine.GetText().Substring(end - endLine.Start); if (!String.IsNullOrWhiteSpace(endText)) { edit.Insert(end, _textView.Options.GetNewLineCharacter()); } } else { _selectEndSpan = true; } } IndentSpan( edit, indentation, _textView.TextBuffer.CurrentSnapshot.GetLineFromPosition(start).LineNumber + 1, // 1st line is already indented _textView.TextBuffer.CurrentSnapshot.GetLineFromPosition(end).LineNumber ); } } // we now need to update any code which was not selected that we just inserted. IndentSpan(edit, baseIndentation, ts[0].iStartLine + 1, ts[0].iEndLine); edit.Apply(); } return(hr); }