How to obtain the absolute position of text cursor in Visual Studio 2010 extension
Tag : chash , By : user135518
Date : March 29 2020, 07:55 AM
like below fixes the issue I am doing exactly the same thing in a current project, so here is the relevant code copy and pasted. I generate the activeWpfTextView object elsewhere using the following answer: Find an IVsTextView or IWpfTextView for a given ProjectItem, in VS 2010 RC extension. private IVsWindowFrame GetWindow()
{
// parent is the Microsoft.VisualStudio.Shell.ToolWindowPane
// containing this UserControl given in the constructor.
var window = (ToolWindowPane)parent.GetIVsWindowPane();
return (IVsWindowFrame)window.Frame;
}
private void DoShow()
{
var window = GetWindow();
var textViewOrigin = (activeWpfTextView as UIElement).PointToScreen(new Point(0, 0));
var caretPos = activeWpfTextView.Caret.Position.BufferPosition;
var charBounds = activeWpfTextView
.GetTextViewLineContainingBufferPosition(caretPos)
.GetCharacterBounds(caretPos);
double textBottom = charBounds.Bottom;
double textX = charBounds.Right;
Guid guid = default(Guid);
double newLeft = textViewOrigin.X + textX - activeWpfTextView.ViewportLeft;
double newTop = textViewOrigin.Y + textBottom - activeWpfTextView.ViewportTop;
window.SetFramePos(VSSETFRAMEPOS.SFP_fMove, ref guid,
(int)newLeft, (int)newTop,
0, 0);
window.Show();
resultsList.Focus();
}
|
Setting cursor position with Visual Studio Extension
Date : March 29 2020, 07:55 AM
To fix this issue I finally got it... You just have to use the TextSelectioninterface where you have the method MoveToPoint. // open the file in a VS code window and activate the pane
Window window = requestedItem.Open(Constants.vsViewKindCode);
window.Activate();
// get the function element and show it
CodeElement function = CodeElementSearcher.GetFunction(requestedItem, myFunctionName);
// get the text of the document
TextSelection textSelection = window.Document.Selection as TextSelection;
// now set the cursor to the beginning of the function
textSelection.MoveToPoint(function.StartPoint);
|
How to debug code compiled with Roslyn in a Visual Studio extension inside current Visual Studio host?
Date : March 29 2020, 07:55 AM
will help you Seems like this is actually impossible. The current visual studio instance cannot debug itself. Process vsProcess = Process.GetCurrentProcess();
string solutionPath = CurrentWorkspace.CurrentSolution.FilePath;
SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText($@"
using System;
using System.Threading.Tasks;
namespace CodeGenApplication
{{
public class Program
{{
public static void Main(string[] args)
{{
Console.ReadLine();
int vsProcessId = Int32.Parse(args[0]);
CodeGenApp.Test(""{solutionPath.Replace(@"\", @"\\")}"", ""{projectName}"", ""{_codeGenProjectName}"");
Console.ReadLine();
}}
}}
}}");
string assemblyName = Path.GetRandomFileName();
Project codeGenProject = CurrentWorkspace.CurrentSolution.Projects.Where(x => x.Name == _codeGenProjectName).FirstOrDefault();
List<MetadataReference> references = codeGenProject.MetadataReferences.ToList();
CSharpCompilation compilation = CSharpCompilation.Create(
assemblyName,
syntaxTrees: new[] { syntaxTree },
references: references,
options: new CSharpCompilationOptions(OutputKind.ConsoleApplication));
// Emit assembly to streams.
EmitResult result = compilation.Emit("CodeGenApplication.exe", "CodeGenApplication.pdb");
if (!result.Success)
{
IEnumerable<Diagnostic> failures = result.Diagnostics.Where(diagnostic =>
diagnostic.IsWarningAsError ||
diagnostic.Severity == DiagnosticSeverity.Error);
}
else
{
Process codeGenProcess = new Process();
codeGenProcess.StartInfo.FileName = "CodeGenApplication.exe";
codeGenProcess.StartInfo.Arguments = vsProcess.Id.ToString();
codeGenProcess.StartInfo.UseShellExecute = false;
codeGenProcess.StartInfo.CreateNoWindow = true;
codeGenProcess.StartInfo.LoadUserProfile = true;
codeGenProcess.StartInfo.RedirectStandardError = true;
codeGenProcess.StartInfo.RedirectStandardInput = true;
codeGenProcess.StartInfo.RedirectStandardOutput = false;
codeGenProcess.Start();
foreach (EnvDTE.Process dteProcess in _dte.Debugger.LocalProcesses)
{
if (dteProcess.ProcessID == codeGenProcess.Id)
{
dteProcess.Attach();
}
}
codeGenProcess.StandardInput.WriteLine("Start");
}
|
Can a language extension written in Visual Studio Code be used in Visual Studio 2017?
Date : March 29 2020, 07:55 AM
I hope this helps you . According to the visual studio docs and especially to this picture it should be possible to migrate that language server to visual studio, too. However it is not possible to use the exact same extension for VS Code as well as for Visual Studio. At least you will have to change the Provider-specific intizialization code (see the picture) to make the server work for Visual Studio, too.
|
How to get the character to the left of cursor in Visual Studio Extension?
Tag : .net , By : Bart van Bragt
Date : March 29 2020, 07:55 AM
To fix the issue you can do I'm trying to get the character on the left of cursor. I've got the handler that intercepts the LineChanged event. , To get the character to the left of the EnvDTE.TextPoint: string CharacterToTheLeft(EnvDTE.TextPoint p)
{
EnvDTE.EditPoint editPoint = p.CreateEditPoint();
editPoint.CharLeft();
return editPoint.GetText(1);
}
EnvDTE.TextSelection ts = startPoint.Parent.Selection;
EnvDTE.EditPoint editPoint = ts.ActivePoint.CreateEditPoint();
|