Code Monkey home page Code Monkey logo

codequery4vscode's Introduction

CodeQuery for VSCode

This is a Visual Studio Code Extension (or plugin) for CodeQuery.

The Visual Studio Code Extension Marketplace page for this extension is ruben2020.codequery4vscode.

CodeQuery is a tool to index, then query or search C, C++, Java, Python, Ruby, Go and Javascript source code.

It builds upon the databases of cscope and Exuberant ctags. It can also work with Universal ctags, which is a drop-in replacement for Exuberant ctags.

The databases of cscope and ctags would be processed by the cqmakedb tool to generate the CodeQuery database file. The tool cscope only works with C, C++ and Java. The database of cscope can also be generated by pycscope for Python and starscope for Ruby, Go and Javascript.

The CodeQuery database file can be queried on Visual Studio Code using this extension. This Visual Studio Code Extension makes use of Codequery CLI tool cqsearch to perform the queries.

Latest version = 0.8.1

Please read CHANGELOG to discover the latest changes in this release.

What types of query can I make with this extension?

  • Symbol
  • Function or macro definition
  • Class or struct
  • Functions calling this function
  • Functions called by this function
  • Calls of this function or macro
  • Class which owns this member or method
  • Members and methods of this class
  • Parent of this class (inheritance)
  • Children of this class (inheritance)
  • Files including this file

What does it cost? How is it licensed?

This software is freeware and free open source software. It can be used in a commercial environment for free, for an unlimited period of time. The same applies to CodeQuery.

This software is licensed under the MIT License. Please see the LICENSE file for more details.

Which platforms are supported?

It has been tested on Visual Studio Code in Linux 64-bit and Windows 10 64-bit. It should work on Mac without any problems, similar to how it works on Linux.

What are the prerequisites or dependencies that I must install, before installing this extension?

You need to install the following:

If you have installed CodeQuery correctly, cqsearch should be accessible on a terminal window from any folder i.e. it's on PATH. This is required.

How do I install this extension?

The Visual Studio Code Extension Marketplace page for this extension is ruben2020.codequery4vscode.

In Visual Studio Code, click on the Extension button on the left panel (or alternatively, press Ctrl+Shift+X) and then search for "codequery4vscode". After this, click on the Install button.

Alternatively, in Visual Studio Code, press Ctrl+P, then enter ext install ruben2020.codequery4vscode, and press Enter.

How do I prepare my source code for use with this extension?

Let's assume that the base folder of your source code is [project_base_path].

The extension will look for the CodeQuery database in [project_base_path]/.vscode/codequery/cq.db exactly.

The CodeQuery database can be rebuilt by the extension using either a Bash script in {project_base_path}/.vscode/codequery/rebuild.sh or a Windows batch file in {project_base_path}/.vscode/codequery/rebuild.bat.

The Bash script or Windows batch file can be called manually or through the codequery4vscode Visual Studio Code extension. It's meant to be executed when the current working directory is [project_base_path]

Let me provide an example here on how to prepare the source code of CodeQuery itself.

In Linux or Mac, follow these steps for C/C++ source code:

cd ~/repo
git clone https://github.com/ruben2020/codequery.git
cd codequery
mkdir -p .vscode/codequery

Here, [project_base_path] is ~/repo/codequery.

Then create the script ~/repo/codequery/.vscode/codequery/rebuild.sh with these contents using vim, gedit or your favorite editor:

#!/bin/bash
rm -f .vscode/codequery/cscope.out
rm -f .vscode/codequery/tags
find . -iname "*.h"    > .vscode/codequery/cscope.files
find . -iname "*.hpp" >> .vscode/codequery/cscope.files
find . -iname "*.hxx" >> .vscode/codequery/cscope.files
find . -iname "*.hh"  >> .vscode/codequery/cscope.files
find . -iname "*.c"   >> .vscode/codequery/cscope.files
find . -iname "*.cpp" >> .vscode/codequery/cscope.files
find . -iname "*.cxx" >> .vscode/codequery/cscope.files
find . -iname "*.cc"  >> .vscode/codequery/cscope.files
cscope -cb -i .vscode/codequery/cscope.files -f .vscode/codequery/cscope.out
ctags --fields=+i -n -L .vscode/codequery/cscope.files -f .vscode/codequery/tags
cd .vscode/codequery
cqmakedb -s cq.db -c cscope.out -t tags -p -d

And then make it executable:

chmod +x ~/repo/codequery/.vscode/codequery/rebuild.sh

You can test the script by calling:

cd ~/repo/codequery/
./.vscode/codequery/rebuild.sh

In Windows, follow these steps for C/C++ source code:

cd c:\repo
git clone https://github.com/ruben2020/codequery.git
cd codequery
md .vscode
md .vscode\codequery

Then create the Windows batch file c:\repo\codequery\.vscode\codequery\rebuild.bat with these contents using Notepad or your favorite editor:

del /Q /F .vscode\codequery\cscope.out
del /Q /F .vscode\codequery\tags
dir /b/a/s *.h    > .vscode\codequery\cscope.files
dir /b/a/s *.hpp >> .vscode\codequery\cscope.files
dir /b/a/s *.hxx >> .vscode\codequery\cscope.files
dir /b/a/s *.hh  >> .vscode\codequery\cscope.files
dir /b/a/s *.c   >> .vscode\codequery\cscope.files
dir /b/a/s *.cpp >> .vscode\codequery\cscope.files
dir /b/a/s *.cxx >> .vscode\codequery\cscope.files
dir /b/a/s *.cc  >> .vscode\codequery\cscope.files
cscope -cb -i .vscode\codequery\cscope.files -f .vscode\codequery\cscope.out
ctags --fields=+i -n -L .vscode\codequery\cscope.files -f .vscode\codequery\tags
cd .vscode\codequery
cqmakedb -s cq.db -c cscope.out -t tags -p -d

You can test the Windows batch file by calling the following on a command terminal window:

cd c:\repo\codequery
.vscode\codequery\rebuild.bat

Please replace the wildcard expressions above with *.java, *.py, *.rb, *.go and *.js respectively for Java, Python, Ruby, Go and Javascript. Details can be found on the CodeQuery page.

You may also want to add .vecode to the .gitignore file on the base folder of your source code.

How do I build or rebuild the CodeQuery database using this extension on Visual Studio Code?

First, open the Command Palette using Ctrl+Shift+P. Alternatively, click View on the Visual Studio Code menu, then select Command Palette....

You will then see this:

Command Palette

Next, type "CodeQuery" into the inputbox. It will narrow down the results. Select CodeQuery: Rebuild database.

Command Palette

It could take a while to complete depending on the number of source code files to index. It will show a pop-up stating if the database rebuild was successful or failed.

If {project_base_path}/.vscode/codequery/rebuild.sh (in Linux or Mac) or {project_base_path}/.vscode/codequery/rebuild.bat (in Windows) cannot be found or cannot be executed (due to insufficient permissions), an error notification will pop-up.

How do I search or query my code using this extension on Visual Studio Code?

First, open the base folder of your source code by clicking on File on the menu of Visual Studio Code, followed by selecting Open Folder.... Alternatively, press Ctrl+K Ctrl+O. If I use the same example as before, this refers to C:\repo\codequery on Windows or /home/johndoe/repo/codequery on Linux, assuming your username on Linux is johndoe.

There are 3 ways to search or query code using this extension:

  • Method 1: Accessing codequery4vscode from the Command Palette, then typing a search phrase into an inputbox
  • Method 2: Selecting text of code from a file, and using that to search, from the right-click dropdown menu
  • Method 3: Clicking on the [Click here to search] line on the codequery4vscode treeview, and then typing a search phrase into an inputbox

The next sections show these.

Method 1 for searching or querying code

First, open the Command Palette using Ctrl+Shift+P. Alternatively, click View on the Visual Studio Code menu, then select Command Palette....

You will then see this:

Command Palette

Next, type "CodeQuery" into the inputbox. It will narrow down the results. Select CodeQuery: Search from input text.

Command Palette

Next, it will show you a quickpick menu with a list of possible search types. In this example, we select 1: Symbol.

Search type selection

Next, it will show you an inputbox, where you can type a search phrase. In this example, we typed fileviewer for fuzzy search. Then press Enter.

For exact string search (including case sensitive), please enclose the search term in quotes like this: "fileviewer".

The path filter can be included in square brackets after the search term.

To search for the term fileviewer as fuzzy search, but restrict it to source code files below the gui folder, type in fileviewer[gui]. To search for the term fileviewer as fuzzy search, but restrict it to *.h files only, type in fileviewer[*.h].

To search for the term fileviewer as exact term search, but restrict it to source code files below the gui folder, type in "fileviewer"[gui]. To search for the term fileviewer as exact term search, but restrict it to *.h files only, type in "fileviewer"[*.h].

Search inputbox

After this, the search results will be shown. How to browse the search results will be explained below.

Method 2 for searching or querying code

First, open a source file from the current project or folder in Visual Studio Code, then make a text selection using the mouse or keyboard, by highlighting some text. In this example, we highlighted "updateListHeaders" in listhandler.cpp, at line 51.

After this, right-click and a dropdown menu will appear. Select CodeQuery: Search from selected text (fuzzy) for fuzzy search, or CodeQuery: Search from selected text (exact) for exact string search (including case sensitive).

Text selection, then right-click

Next, it will show you a quickpick menu with a list of possible search types. In this example, we select 1: Symbol.

Search type selection

After this, the search results will be shown. How to browse the search results will be explained below.

Method 3 for searching or querying code

First, click the CodeQuery icon on the leftmost panel. This will reveal the codequery4vscode treeview on the left side.

codequery4vscode treeview

After this, click on [Click here to search] on the codequery4vscode treeview.

Next, it will show you a quickpick menu with a list of possible search types. In this example, we select 1: Symbol.

Search type selection

Next, it will show you an inputbox, where you can type a search phrase. In this example, we typed fileviewer for fuzzy search. Then press Enter.

For exact string search (including case sensitive), please enclose the search term in quotes like this: "fileviewer".

The path filter can be included in square brackets after the search term.

To search for the term fileviewer as fuzzy search, but restrict it to source code files below the gui folder, type in fileviewer[gui]. To search for the term fileviewer as fuzzy search, but restrict it to *.h files only, type in fileviewer[*.h].

To search for the term fileviewer as exact term search, but restrict it to source code files below the gui folder, type in "fileviewer"[gui]. To search for the term fileviewer as exact term search, but restrict it to *.h files only, type in "fileviewer"[*.h].

Search inputbox

After this, the search results will be shown. How to browse the search results will be explained below.

How to browse the search results?

The search results will be shown on the codequery4vscode treeview on the left side. A summary of the search results is shown on top.

Below that, a list of files where the search results appear in, would be shown.

Search results1

Select a file on the list to expand it, then select a line which represents a result. In this example, we selected cli/main_cli.cpp and selected the line 181: if (resultlst.result_type == sqlquery.... Then the file main_cli.cpp will be opened and it will reveal line 181. Select other files and lines to see more results.

Search results2

The above is based on the search type of 1: Symbol.

Click on [Search again with another type] under Search Summary, to repeat the search but to select a different search type.

Next, it will show you a quickpick menu with a list of possible search types. In this example, we select 3: Class or Struct.

Search type selection

Next, the results will be updated as follows.

Search results3

How do I contact the authors for support, issues, bug reports, fix patches, feature requests etc.?

Please see the email address below, and also the Issues tab in GitHub.

Email address:
Contact address

Website: codequery4vscode website

How can I contribute?

List of Contributors

ruben2020
(More welcomed)

codequery4vscode's People

Contributors

dependabot[bot] avatar ruben2020 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

galaxyraiser

codequery4vscode's Issues

Filter search results

Hello!
The extension is pretty nice in comparison with scope4code and cscope-code, but the latter has a nice feature of filtering results based on the input string - I suppose it would be a nice feature for codequery4vscode as well.

For example, I want to find a definition of getname function in the Linux kernel source tree for 5.1.9 version. codequery4vscode finds a lot of various functions that contain a getname substring in its name, but I need to find getname and not *getname*, so it would be better to either make other options with strict searching or add a filtering functionality

Thanks in advance :)

Feature Request: 'Codequery-Build' cmd triggers (user-modifiable) script to build cq.db...

Instead of requiring the user to manually launch all the cmds that aggregate and assemble the cq.db database for CodeQuery to use, I propose the plugin install the following user-modifiable scripts:

  • cscope-build.sh
  • ctags-build.sh
  • cq-build.sh

cq-build.sh:

#!/bin/sh
cd ${CQ_WS_DIR}   # = <workspace>/.vscode/codequery
exec ${CQ_PLUGIN_BIN}/cscope-build.sh
exec ${CQ_PLUGIN_BIN}/ctags-build.sh
${CQ_PLUGIN_BIN}/cqmakedb -s ${CQ_WS_DIR}/cq.db -c ${CQ_WS_DIR}/cscope.out -t ${CQ_WS_DIR}/tags -p

cscope-build.sh:

#!/bin/sh
find ${WS} -iname "*.c"    > ${CQ_WS_DIR}/cscope.files
find ${WS} -iname "*.cpp" >> ${CQ_WS_DIR}/cscope.files
find ${WS} -iname "*.cxx" >> ${CQ_WS_DIR}/cscope.files
find ${WS} -iname "*.cc " >> ${CQ_WS_DIR}/cscope.files
find ${WS} -iname "*.h"   >> ${CQ_WS_DIR}/cscope.files
find ${WS} -iname "*.hpp" >> ${CQ_WS_DIR}/cscope.files
find ${WS} -iname "*.hxx" >> ${CQ_WS_DIR}/cscope.files
find ${WS} -iname "*.hh " >> ${CQ_WS_DIR}/cscope.files
cscope -cbf ${CQ_WS_DIR}/cscope_c.out

# Uncomment below if using pycscope
# find ${WS} -iname "*.py"    > ${CQ_WS_DIR}/pycscope.files
# pycscope -i ${CQ_WS_DIR}/pycscope.files -f ${CQ_WS_DIR}/cscope_py.out

# Uncomment below if using starscope
# find ${WS} -iname "*.rb"    > ${CQ_WS_DIR}/cscope.files
# find ${WS} -iname "*.go"    >> ${CQ_WS_DIR}/cscope.files
# find ${WS} -iname "*.js"    >> ${CQ_WS_DIR}/cscope.files
# starscope -e cscope,${CQ_WS_DIR}

ctags-build.sh:

#!/bin/sh
ctags --fields=+i -n -L ${CQ_WS_DIR}/cscope.files -f ${CQ_WS_DIR}/tags

Hopefully this is enough to give you a rough idea of what I mean. The key is that the user can adjust locations, etc. as needed to integrate with other tools and systems they might be using, etc.

support filter on query result

Hi Developers,

I suggest is it possible to add filter base on search result.
sometimes, we find many tags.

could we have another level-2 text filter or type filter (marco/function) ?

Feature Request: Allow setting (workspace-relative) location for cq.db file in extension prefs.

As I already have .vscode programmed into all my .gitignore's and equivalents, I'd rather keep cq.db, cscope.out, and the other components that build cq.db all together inside {workspace}/.vscode or even better {workspace}/.vscode/codequery/. I'd love to be able to set, ideally, workspace/.vscode/codequery/ as where the plugin should look for the associate cq.db file to use.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.