Last active
April 3, 2024 06:59
-
-
Save Sharlock93/0aaf8119eb6e7000947f096780bda32e to your computer and use it in GitHub Desktop.
Vim & Visual Studio Integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vim9script | |
def SetupDTEContext() | |
py3 << EOF | |
import vim | |
visual_studio_dtes = [0] # 1 based | |
selected_visual_studio_dte = None | |
def SetDTE(): | |
global selected_visual_studio_dte | |
global visual_studio_dtes | |
index = int(vim.eval('g:sh_dte_selected_index')) | |
selected_visual_studio_dte = visual_studio_dtes[index] | |
vim.command('g:dte_selected = 1') | |
EOF | |
enddef | |
def SetDTE(a: any, res: number) | |
g:sh_dte_selected_index = res | |
py3 SetDTE() | |
enddef | |
def! g:GetVsList() | |
py3 << EOF | |
import vim | |
from win32com.client import pythoncom, Dispatch | |
binder = pythoncom.CreateBindCtx(0) | |
ob = pythoncom.GetRunningObjectTable() | |
l = [] | |
visual_studio_dtes = [0] | |
for x in ob.EnumRunning(): | |
disp = x.GetDisplayName(binder, x) | |
if disp.startswith("!VisualStudio.DTE"): | |
s = Dispatch(ob.GetObject(x).QueryInterface(pythoncom.IID_IDispatch)) | |
visual_studio_dtes.append(s) | |
l.append(s.Solution.FullName) | |
popup = vim.Function('popup_menu') | |
popup(l, { 'callback' : 'SetDTE' }) | |
EOF | |
enddef | |
if !exists('g:sh_dte_context_setup') | |
SetupDTEContext() | |
g:sh_dte_context_setup = true | |
endif | |
def! g:OpenInVisualStudio() | |
if !exists('g:dte_selected') | |
g:GetVsList() | |
else | |
py3 << EOF | |
import vim | |
from win32com import client | |
vs = selected_visual_studio_dte | |
line = vim.Function("line")('.') | |
file = vim.Function('expand')('%:p') | |
vs.ExecuteCommand("Open", file.decode('utf-8')) | |
vs.ExecuteCommand("GotoLn", line) | |
vs.ExecuteCommand("Debug.ToggleBreakpoint") | |
vs.MainWindow.Activate | |
EOF | |
endif | |
enddef | |
def! g:StartVisualStudioDebugging() | |
py3 << EOF | |
from win32com import client as CL | |
vs = CL.Dispatch("VisualStudio.DTE") | |
vs.ExecuteCommand("Debug.Start") | |
EOF | |
enddef | |
defcompile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment