diff --git a/dlangide_msvc.visualdproj b/dlangide_msvc.visualdproj index 12fa97d..43e4ed1 100644 --- a/dlangide_msvc.visualdproj +++ b/dlangide_msvc.visualdproj @@ -52,6 +52,7 @@ 0 $(CC) -c 1 + 0 $(DMDInstallDir)windows\bin\dmd.exe $(ProjectDir)/../dlangui/src $(ProjectDir)/../dlangui/3rdparty $(ProjectDir)/../dlangui/deps/DerelictGL3/source $(ProjectDir)/../dlangui/deps/DerelictUtil/source $(ProjectDir)/../dlangui/deps/DerelictFT/source $(ProjectDir)/../dlangui/deps/DerelictSDL2/source $(ProjectDir)/../dlangui/deps/libdparse/src $(ProjectDir)/../DerelictLLDB/source views views/res views/res/i18n views/res/mdpi views/res/hdpi @@ -154,6 +155,7 @@ 0 $(CC) -c 1 + 0 $(DMDInstallDir)windows\bin\dmd.exe $(ProjectDir)/../dlangui/src $(ProjectDir)/../dlangui/3rdparty $(ProjectDir)/../dlangui/deps/DerelictGL3/source $(ProjectDir)/../dlangui/deps/DerelictUtil/source $(ProjectDir)/../dlangui/deps/DerelictFT/source $(ProjectDir)/../dlangui/deps/DerelictSDL2/source $(ProjectDir)/../dlangui/deps/libdparse/src $(ProjectDir)/../DerelictLLDB/source views views/res views/res/i18n views/res/mdpi views/res/hdpi @@ -256,6 +258,7 @@ 0 $(CC) -c -v 1 + 0 $(DMDInstallDir)windows\bin\dmd.exe $(ProjectDir)/../dlangui/src $(ProjectDir)/../dlangui/3rdparty $(ProjectDir)/../dlangui/deps/DerelictGL3/source $(ProjectDir)/../dlangui/deps/DerelictUtil/source $(ProjectDir)/../dlangui/deps/DerelictFT/source $(ProjectDir)/../dlangui/deps/DerelictSDL2/source $(ProjectDir)/../dlangui/deps/libdparse/src $(ProjectDir)/../DerelictLLDB/source views views/res views/res/i18n views/res/mdpi views/res/hdpi @@ -358,6 +361,7 @@ 0 $(CC) -c 1 + 0 $(DMDInstallDir)windows\bin\dmd.exe $(ProjectDir)/../dlangui/src $(ProjectDir)/../dlangui/3rdparty $(ProjectDir)/../dlangui/deps/DerelictGL3/source $(ProjectDir)/../dlangui/deps/DerelictUtil/source $(ProjectDir)/../dlangui/deps/DerelictFT/source $(ProjectDir)/../dlangui/deps/DerelictSDL2/source $(ProjectDir)/../dlangui/deps/libdparse/src $(ProjectDir)/../DerelictLLDB/source views views/res views/res/i18n views/res/mdpi views/res/hdpi @@ -460,6 +464,7 @@ 0 $(CC) -c 1 + 0 $(DMDInstallDir)windows\bin\dmd.exe $(ProjectDir)/../dlangui/src $(ProjectDir)/../dlangui/3rdparty $(ProjectDir)/../dlangui/deps/DerelictGL3/source $(ProjectDir)/../dlangui/deps/DerelictUtil/source $(ProjectDir)/../dlangui/deps/DerelictFT/source $(ProjectDir)/../dlangui/deps/DerelictSDL2/source $(ProjectDir)/../dlangui/deps/libdparse/src $(ProjectDir)/../DerelictLLDB/source views views/res views/res/i18n views/res/mdpi views/res/hdpi @@ -562,6 +567,7 @@ 0 $(CC) -c -v 1 + 0 $(DMDInstallDir)windows\bin\dmd.exe $(ProjectDir)/../dlangui/src $(ProjectDir)/../dlangui/3rdparty $(ProjectDir)/../dlangui/deps/DerelictGL3/source $(ProjectDir)/../dlangui/deps/DerelictUtil/source $(ProjectDir)/../dlangui/deps/DerelictFT/source $(ProjectDir)/../dlangui/deps/DerelictSDL2/source $(ProjectDir)/../dlangui/deps/libdparse/src $(ProjectDir)/../DerelictLLDB/source views views/res views/res/i18n views/res/mdpi views/res/hdpi diff --git a/src/dlangide/tools/d/dcdinterface.d b/src/dlangide/tools/d/dcdinterface.d index 2f4bb12..07ac8ec 100644 --- a/src/dlangide/tools/d/dcdinterface.d +++ b/src/dlangide/tools/d/dcdinterface.d @@ -48,7 +48,8 @@ class DCDTask { void createRequest() { request.sourceCode = cast(ubyte[])_content; request.fileName = _filename; - request.cursorPosition = _index; + request.cursorPosition = _index; + request.importPaths = _importPaths; } void performRequest() { // override @@ -69,11 +70,27 @@ class DCDTask { } } +class ModuleCacheAccessor { + import dsymbol.modulecache; + //protected ASTAllocator _astAllocator; + protected ModuleCache _moduleCache; + this(in string[] importPaths) { + _moduleCache = ModuleCache(new ASTAllocator); + _moduleCache.addImportPaths(importPaths); + } + protected ModuleCache * getModuleCache(in string[] importPaths) { + _moduleCache.addImportPaths(importPaths); + return &_moduleCache; + } +} + /// Async interface to DCD class DCDInterface : Thread { import dsymbol.modulecache; - protected ModuleCache _moduleCache = ModuleCache(new ASTAllocator); + //protected ASTAllocator _astAllocator; + //protected ModuleCache * _moduleCache; + ModuleCacheAccessor _moduleCache; protected BlockingQueue!DCDTask _queue; this() { @@ -88,13 +105,37 @@ class DCDInterface : Thread { join(); destroy(_queue); _queue = null; + if (_moduleCache) { + destroyModuleCache(); + } + } + + protected void destroyModuleCache() { + if (_moduleCache) { + Log.d("DCD: destroying module cache"); + destroy(_moduleCache); + _moduleCache = null; + /* + if (_astAllocator) { + _astAllocator.deallocateAll(); + destroy(_astAllocator); + _astAllocator = null; + } + */ + } } protected ModuleCache * getModuleCache(in string[] importPaths) { // TODO: clear cache if import paths removed or changed // hold several module cache instances - make cache of caches - _moduleCache.addImportPaths(importPaths); - return &_moduleCache; + //destroyModuleCache(); + //if (!_astAllocator) + // _astAllocator = new ASTAllocator; + if (!_moduleCache) { + _moduleCache = new ModuleCacheAccessor(importPaths); + } + return _moduleCache.getModuleCache(importPaths); + //return _moduleCache; } void threadFunc() { @@ -104,7 +145,8 @@ class DCDInterface : Thread { if (!_queue.get(task)) break; if (task && !task.cancelled) { - Log.d("Execute DCD task"); + import std.file : getcwd; + Log.d("Execute DCD task; current dir=", getcwd); task.execute(); Log.d("DCD task execution finished"); } @@ -141,7 +183,7 @@ class DCDInterface : Thread { override void performRequest() { AutocompleteResponse response = getDoc(request, *getModuleCache(_importPaths)); - result.docComments = response.docComments; + result.docComments = response.docComments.dup; result.result = DCDResult.SUCCESS; debug(DCD) Log.d("DCD doc comments:\n", result.docComments); @@ -176,7 +218,7 @@ class DCDInterface : Thread { override void performRequest() { AutocompleteResponse response = findDeclaration(request, *getModuleCache(_importPaths)); - result.fileName = response.symbolFilePath; + result.fileName = response.symbolFilePath.dup; result.offset = response.symbolLocation; result.result = DCDResult.SUCCESS; diff --git a/src/dlangide/tools/d/deditortool.d b/src/dlangide/tools/d/deditortool.d index 9e81d68..bde0927 100644 --- a/src/dlangide/tools/d/deditortool.d +++ b/src/dlangide/tools/d/deditortool.d @@ -27,12 +27,29 @@ class DEditorTool : EditorTool cancelGetCompletions(); } + static bool isIdentChar(char ch) { + return ch == '_' || (ch >= 'a' && ch <='z') || (ch >= 'A' && ch <='Z') || ((ch & 0x80) != 0); + } + static bool isAtWord(string content, size_t byteOffset) { + if (byteOffset >= content.length) + return false; + if (isIdentChar(content[byteOffset])) + return true; + if (byteOffset > 0 && isIdentChar(content[byteOffset - 1])) + return true; + if (byteOffset + 1 < content.length && isIdentChar(content[byteOffset + 1])) + return true; + return false; + } + DCDTask _getDocCommentsTask; override void getDocComments(DSourceEdit editor, TextPosition caretPosition, void delegate(string[]) callback) { cancelGetDocComments(); string[] importPaths = editor.importPaths(); string content = toUTF8(editor.text); auto byteOffset = caretPositionToByteOffset(content, caretPosition); + if (!isAtWord(content, byteOffset)) + return; _getDocCommentsTask = _frame.dcdInterface.getDocComments(editor.window, importPaths, editor.filename, content, byteOffset, delegate(DocCommentsResultSet output) { if(output.result == DCDResult.SUCCESS) { auto doc = output.docComments; diff --git a/src/dlangide/ui/settings.d b/src/dlangide/ui/settings.d index 0cd34c1..6fb134a 100644 --- a/src/dlangide/ui/settings.d +++ b/src/dlangide/ui/settings.d @@ -163,7 +163,7 @@ SettingsPage createProjectSettingsPages() { SettingsPage dbg = res.addChild("debug", UIString.fromRaw("Run and Debug"d)); dbg.addStringEdit("debug/run_args", UIString.fromRaw("Command line args"d), ""); dbg.addDirNameEdit("debug/working_dir", UIString.fromRaw("Working directory"d), ""); - dbg.addCheckbox("debug/external_console", UIString.fromRaw("Run in external console"d), true); + dbg.addCheckbox("debug/external_console", UIString.fromRaw("Run in external console"d), false); return res; } diff --git a/src/dlangide/workspace/project.d b/src/dlangide/workspace/project.d index bb2fd47..a4fef92 100644 --- a/src/dlangide/workspace/project.d +++ b/src/dlangide/workspace/project.d @@ -547,7 +547,7 @@ class Project : WorkspaceItem { @property bool runInExternalConsole() { // TODO - return true; + return settings.runInExternalConsole; } ProjectFolder findItems(string[] srcPaths) { diff --git a/src/dlangide/workspace/projectsettings.d b/src/dlangide/workspace/projectsettings.d index 2beb259..6f34cf4 100644 --- a/src/dlangide/workspace/projectsettings.d +++ b/src/dlangide/workspace/projectsettings.d @@ -67,6 +67,10 @@ class ProjectSettings : SettingsFile { return null; return cfg; } + + @property bool runInExternalConsole() { + return debugSettings.getBoolean("external_console", true); + } } /// join parameter lists separating with space