From 291ef69fe2f36f030a31c736a9817d7bde73195f Mon Sep 17 00:00:00 2001 From: Rainer Schuetze Date: Sun, 10 May 2015 17:30:05 +0200 Subject: [PATCH] - reload text buffer after "Compile and Disassemble" - do not bail out on bad line number offsets --- VERSION | 2 +- sdk/vsi.visualdproj | 228 ++++++++++++++++++++++---------------------- visuald/dlangsvc.d | 87 ++++++++++++++++- visuald/fileutil.d | 9 +- 4 files changed, 204 insertions(+), 122 deletions(-) diff --git a/VERSION b/VERSION index 02e9c5a7..0bfb3718 100644 --- a/VERSION +++ b/VERSION @@ -2,4 +2,4 @@ #define VERSION_MINOR 3 #define VERSION_REVISION 41 #define VERSION_BETA -beta -#define VERSION_BUILD 3 +#define VERSION_BUILD 4 diff --git a/sdk/vsi.visualdproj b/sdk/vsi.visualdproj index ab81888d..d0c107bd 100644 --- a/sdk/vsi.visualdproj +++ b/sdk/vsi.visualdproj @@ -1272,9 +1272,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - @@ -1283,23 +1373,18 @@ - - - - - @@ -1331,7 +1416,6 @@ - @@ -1342,14 +1426,8 @@ - - - - - - @@ -1360,17 +1438,12 @@ - - - - - @@ -1383,121 +1456,48 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/visuald/dlangsvc.d b/visuald/dlangsvc.d index 9a41386c..f6b7a742 100644 --- a/visuald/dlangsvc.d +++ b/visuald/dlangsvc.d @@ -1046,12 +1046,89 @@ class CodeDefViewContext : DComObject, IVsCodeDefViewContext } ///////////////////////////////////////////////////////////////////////// +HRESULT reloadTextBuffer(string fname) +{ + IVsRunningDocumentTable pRDT = queryService!(IVsRunningDocumentTable); + if(!pRDT) + return E_FAIL; + scope(exit) release(pRDT); + + auto docname = _toUTF16z(fname); + IVsHierarchy srpIVsHierarchy; + VSITEMID vsItemId = VSITEMID_NIL; + IUnknown srpIUnknown; + VSDOCCOOKIE vsDocCookie = VSDOCCOOKIE_NIL; + HRESULT hr = pRDT.FindAndLockDocument(/* [in] VSRDTFLAGS dwRDTLockType */ RDT_NoLock, + /* [in] LPCOLESTR pszMkDocument */ docname, + /* [out] IVsHierarchy **ppHier */ &srpIVsHierarchy, + /* [out] VSITEMID *pitemid */ &vsItemId, + /* [out] IUnknown **ppunkDocData */ &srpIUnknown, + /* [out] VSCOOKIE *pdwCookie */ &vsDocCookie); + + // FindAndLockDocument returns S_FALSE if the doc is not in the RDT + if (hr != S_OK) + return hr; + + scope(exit) release(srpIUnknown); + scope(exit) release(srpIVsHierarchy); + + IVsTextLines textBuffer = qi_cast!IVsTextLines(srpIUnknown); + if(!textBuffer) + if(auto bufferProvider = qi_cast!IVsTextBufferProvider(srpIUnknown)) + { + bufferProvider.GetTextBuffer(&textBuffer); + release(bufferProvider); + } + if(!textBuffer) + return returnError(E_FAIL); + scope(exit) release(textBuffer); + + if (auto docdata = qi_cast!IVsPersistDocData(srpIUnknown)) + docdata.ReloadDocData(RDD_IgnoreNextFileChange|RDD_RemoveUndoStack); + + return textBuffer.Reload(true); +} + +IVsTextView findCodeDefinitionWindow() +{ + IVsCodeDefView cdv = queryService!(SVsCodeDefView,IVsCodeDefView); + if (!cdv) + return null; + scope(exit) release(cdv); + + IVsTextManager textmgr = queryService!(VsTextManager, IVsTextManager); + if(!textmgr) + return null; + scope(exit) release(textmgr); + + IVsEnumTextViews enumTextViews; + + // Passing null will return all available views, at least according to the documentation + // unfortunately, it returns error E_INVALIDARG, said to be not implemented + HRESULT hr = textmgr.EnumViews(null, &enumTextViews); + if (!enumTextViews) + return null; + scope(exit) release(enumTextViews); + + IVsTextView tv; + DWORD fetched; + while(enumTextViews.Next(1, &tv, &fetched) == S_OK && fetched == 1) + { + BOOL result; + if (cdv.IsCodeDefView(tv, &result) == S_OK && result) + return tv; + } + return null; +} + bool jumpToDefinitionInCodeWindow(string symbol, string filename, int line, int col, bool forceShow) { IVsCodeDefView cdv = queryService!(SVsCodeDefView,IVsCodeDefView); if (cdv is null) return false; - if (cdv.IsVisible() != S_OK) + scope(exit) release(cdv); + + if (!forceShow && cdv.IsVisible() != S_OK) return false; CodeDefViewContext context = newCom!CodeDefViewContext(symbol, filename, line, col); @@ -1059,7 +1136,8 @@ bool jumpToDefinitionInCodeWindow(string symbol, string filename, int line, int if (forceShow) { - cdv.ShowWindow(); + if (cdv.IsVisible() != S_OK) + cdv.ShowWindow(); cdv.ForceIdleProcessing(); } return true; @@ -1401,9 +1479,12 @@ class Source : DisposingComObject, IVsUserDataEvents, IVsTextLinesEvents, IVsTex // force update to Code Definition Window auto langsvc = Package.GetLanguageService(); int line, idx; - if (langsvc.mLastActiveView && langsvc.mLastActiveView.mView) + if (langsvc.mLastActiveView && langsvc.mLastActiveView.mView && + langsvc.mLastActiveView.mCodeWinMgr.mSource == this) langsvc.mLastActiveView.mView.GetCaretPos(&line, &idx); + reloadTextBuffer(mDisasmFile); + int asmline = getLineInDisasm(line); jumpToDefinitionInCodeWindow("", mDisasmFile, asmline, 0, true); } diff --git a/visuald/fileutil.d b/visuald/fileutil.d index f5d23ac8..7ba1d930 100644 --- a/visuald/fileutil.d +++ b/visuald/fileutil.d @@ -204,7 +204,7 @@ static struct SymLineInfo { string sym; int firstLine; - int[] offsets; + uint[] offsets; } // map symbol + offset to line in disasm dump @@ -269,7 +269,7 @@ SymLineInfo[string] readDisasmFile(string asmfile) rematch = match(line, reoff2); if (!rematch.empty()) { - int off = rematch.captures[1].to!int(16); + uint off = rematch.captures[1].to!uint(16); info.offsets ~= off; } else if (info.sym.length) @@ -376,8 +376,8 @@ LineInfo[] readLineInfoFile(string linefile, string srcfile) auto rematch = match(line, reoffline); if (!rematch.empty()) { - int off = rematch.captures[1].to!int(16); - int ln = rematch.captures[2].to!int(10); + int off = rematch.captures[1].to!uint(16); + int ln = rematch.captures[2].to!uint(10); if (ln >= lineInfos.length) lineInfos.length = ln + 100; if (lineInfos[ln].sym.ptr is null) @@ -402,6 +402,7 @@ File: WindowsApp1\winmain.d Off 0x0: Line 11 Off 0xc: Line 13 Off 0x19: Line 14 + Off 0xfffffffe: Line 16" /* bad offset generated by DMD */ " "; auto deleteme = "deleteme"; std.file.write(deleteme, dumpline);