Skip to content

Commit

Permalink
ctagsd: a scope can be function, class, struct or namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
eranif committed Feb 2, 2022
1 parent f8d796b commit 7e04f0c
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CodeLite/tags_options_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ TagsOptionsData::TagsOptionsData()
, m_clangOptions(0)
, m_clangBinary("")
, m_clangCachePolicy(TagsOptionsData::CLANG_CACHE_ON_FILE_LOAD)
, m_ccNumberOfDisplayItems(50)
, m_ccNumberOfDisplayItems(150)
, m_version(0)
{
// Initialize defaults
Expand Down
3 changes: 2 additions & 1 deletion CodeLite/tags_storage_sqlite3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1893,7 +1893,8 @@ TagEntryPtr TagsStorageSQLite::GetScope(const wxString& filename, int line_numbe

wxString sql;
sql << "select * from tags where file='" << filename << "' and line <= " << line_number
<< " and name NOT LIKE '__anon%' and KIND NOT IN ('parameter') order by line desc limit 1";
<< " and name NOT LIKE '__anon%' and KIND IN ('function', 'class', 'struct', 'namespace') order by line desc "
"limit 1";
clDEBUG1() << "Running SQL:" << sql << endl;
std::vector<TagEntryPtr> tags;
DoFetchTags(sql, tags);
Expand Down
15 changes: 9 additions & 6 deletions codelite_terminal/main.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include <wx/app.h>
#include <wx/event.h>
#include "MainFrame.h"
#include <wx/image.h>
#include "clPersistenceManager.h"
#include "wxTerminalOptions.h"

#include <iostream>
#include <thread>
#include <wx/app.h>
#include <wx/cmdline.h>
#include "wxTerminalOptions.h"
#include <wx/event.h>
#include <wx/image.h>
#include <wx/persist.h>
#include "clPersistenceManager.h"

//#ifdef __WXMSW__
// void RedirectIOToConsole()
Expand Down Expand Up @@ -78,7 +79,9 @@ class MainApp : public wxApp
HINSTANCE user32Dll = LoadLibrary(L"User32.dll");
if(user32Dll) {
SetProcessDPIAwareFunc pFunc = (SetProcessDPIAwareFunc)GetProcAddress(user32Dll, "SetProcessDPIAware");
if(pFunc) { pFunc(); }
if(pFunc) {
pFunc();
}
FreeLibrary(user32Dll);
}
#endif
Expand Down
10 changes: 5 additions & 5 deletions ctagsd/ctagsd.project
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<Project Name="libCodeLite"/>
<Project Name="ctagsdlib"/>
</Dependencies>
<Dependencies Name="Debug">
<Project Name="libCodeLite"/>
<Project Name="ctagsdlib"/>
</Dependencies>
<Settings Type="Executable">
<GlobalSettings>
<Compiler Options="" C_Options="" Assembler="">
Expand Down Expand Up @@ -44,7 +48,7 @@
<Library Value="ctagsdlib"/>
</Linker>
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="$(ProjectName).exe" IntermediateDirectory="" Command="$(WorkspacePath)/build-$(WorkspaceConfiguration)/bin/$(OutputFile)" CommandArguments="--port 45634 --log-level DBG" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(WorkspacePath)/build-$(WorkspaceConfiguration)/lib" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
<General OutputFile="$(ProjectName).exe" IntermediateDirectory="" Command="$(WorkspacePath)/build-$(WorkspaceConfiguration)/bin/$(OutputFile)" CommandArguments="--port 45638 --log-level DBG" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(WorkspacePath)/build-$(WorkspaceConfiguration)/lib" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
<BuildSystem Name="CodeLite Makefile Generator"/>
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
<![CDATA[]]>
Expand Down Expand Up @@ -143,8 +147,4 @@
</Completion>
</Configuration>
</Settings>
<Dependencies Name="Debug">
<Project Name="libCodeLite"/>
<Project Name="ctagsdlib"/>
</Dependencies>
</CodeLite_Project>
2 changes: 1 addition & 1 deletion ctagsd/lib/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CTagsdSettings
vector<pair<wxString, wxString>> m_types;
wxString m_codelite_indexer;
wxString m_ignore_spec = ".git/;.svn/;/build/;/build-;CPack_Packages/;CMakeFiles/";
size_t m_limit_results = 50;
size_t m_limit_results = 150;
wxString m_settings_dir;

private:
Expand Down
21 changes: 21 additions & 0 deletions ctagsd/tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ TEST_FUNC(test_parsing_of_function_parameter)
auto vars = scanner.GetVariablesMap();
CHECK_BOOL(vars.empty());
}
{
CxxVariableScanner scanner(cc_locals_with_typedef, eCxxStandard::kCxx11, {}, false);
auto vars = scanner.GetVariablesMap();
CHECK_BOOL(!vars.empty());
CHECK_BOOL(vars.count("m_options") != 0);
}
{
CxxVariableScanner scanner(cc_test_function_calls_parsing, eCxxStandard::kCxx11, {}, false);
auto vars = scanner.GetVariablesMap();
Expand Down Expand Up @@ -170,6 +176,21 @@ TEST_FUNC(text_cxx_assignment_from_global_method)
return true;
}

TEST_FUNC(text_cxx_cc_with_problematic_typedef)
{
ENSURE_DB_LOADED();
wxString filepath = R"(C:\src\codelite\codelite_terminal\main.cpp)";

if(wxFileExists(filepath)) {
{
completer->set_text(cc_locals_with_typedef, filepath, 88);
auto resolved = completer->code_complete("m_options.", {}, nullptr);
CHECK_NOT_NULL(resolved);
}
}
return true;
}

TEST_FUNC(TestLSPLocation)
{
ENSURE_DB_LOADED();
Expand Down
90 changes: 90 additions & 0 deletions ctagsd/tests/strings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -982,3 +982,93 @@ CxxVariable::Vec_t CxxVariableScanner::GetVariables(bool sort)
OptimizeBuffer(m_buffer, strippedBuffer);
CxxVariable::Vec_t vars = DoGetVariables(strippedBuffer, sort);
)";

const wxString cc_locals_with_typedef = R"(
#include <wx/app.h>
#include <wx/event.h>
#include "MainFrame.h"
#include <wx/image.h>
#include <iostream>
#include <thread>
#include <wx/cmdline.h>
#include "wxTerminalOptions.h"
#include <wx/persist.h>
#include "clPersistenceManager.h"
//#ifdef __WXMSW__
// void RedirectIOToConsole()
//{
// AllocConsole();
// freopen("CON", "wb", stdout);
// freopen("CON", "wb", stderr);
// freopen("CON", "r", stdin); // Note: "r", not "w"
//}
//#endif
static const wxCmdLineEntryDesc cmdLineDesc[] = {
// Switches
{ wxCMD_LINE_SWITCH, "v", "version", "Print current version", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_SWITCH, "h", "help", "Print usage", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_SWITCH, "w", "wait", "Wait for any key to be pressed before exiting", wxCMD_LINE_VAL_STRING,
wxCMD_LINE_PARAM_OPTIONAL },
// Options
{ wxCMD_LINE_OPTION, "p", "print-tty", "Print the terminals tty (*nix only) into file", wxCMD_LINE_VAL_STRING,
wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_OPTION, "t", "title", "Set the console title", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_OPTION, "d", "working-directory", "Set the working directory", wxCMD_LINE_VAL_STRING,
wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_OPTION, "c", "command", "Command to execute", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_OPTION, "f", "file", "File contains command to execute", wxCMD_LINE_VAL_STRING,
wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_NONE }
};
class MyPersistenceManager : public wxPersistenceManager
{
wxFileConfig* m_config = nullptr;
public:
MyPersistenceManager()
{
wxFileName localFile(wxStandardPaths::Get().GetUserDataDir(), "persistency.ini");
m_config = new wxFileConfig("codelite-terminal", "CodeLite", localFile.GetFullPath());
}
~MyPersistenceManager() { wxDELETE(m_config); }
wxConfigBase* GetConfig() const { return m_config; }
};
// Define the MainApp
class MainApp : public wxApp
{
MyPersistenceManager* m_persistency = nullptr;
public:
MainApp() {}
virtual ~MainApp() { wxDELETE(m_persistency); }
virtual bool OnInit()
{
SetAppName("codelite-terminal");
wxFileName configDir(wxStandardPaths::Get().GetUserDataDir(), "");
configDir.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
m_persistency = new MyPersistenceManager();
wxPersistenceManager::Set(*m_persistency);
wxTerminalOptions& m_options = wxTerminalOptions::Get();
// m_persistencManager = new clPersistenceManager();
// wxPersistenceManager::Set(*m_persistencManager);
#ifdef __WXMSW__
typedef BOOL WINAPI (*SetProcessDPIAwareFunc)();
HINSTANCE user32Dll = LoadLibrary(L"User32.dll");
if(user32Dll) {
SetProcessDPIAwareFunc pFunc = (SetProcessDPIAwareFunc)GetProcAddress(user32Dll, "SetProcessDPIAware");
if(pFunc) { pFunc(); }
FreeLibrary(user32Dll);
}
#endif
wxCmdLineParser parser(wxApp::argc, wxApp::argv);
parser.SetDesc(cmdLineDesc);
const wxArrayString& argv = wxApp::argv.GetArguments();
)";

0 comments on commit 7e04f0c

Please sign in to comment.