xulion / scope4code

cscope support for visual studio code
MIT License
21 stars 8 forks source link

Add support for multi-folder workspace #69

Open arnonshp opened 2 years ago

arnonshp commented 2 years ago

In VS code there is an option to add several folders to one workspace. The folders are then specified in VS code workspace file as follows: "folders": [ { "path": "fold1" }, { "path": "fold1" } ] I noticed that when building the cscope DB, it runs only on the first folder in that list. Please add support for multi-folder workspace, so that the build DB command will go over all folders in the workspace and build a DB for each one. In addition, when a function is selected to find the functions calling it (or vice versa) the scope4code should search the DBs in all folders, and not only under the path where the editor's open file is located (would be even better to add a setting whether the search will be limited to the folder where the file is located or span across all folders in the workspace).

xulion commented 2 years ago

Arnonshp,

Multi-folder is actually supported already even before vscode supports that. you can add as many as folders under setting "scope4code.sourceCodePaths" like below:

    "scope4code.sourceCodePaths": [
        "${workspaceRoot}/../"
    ],

Let me know if this solves your problem.

Leon

arnonshp commented 2 years ago

Ok, your comment helped me find the issue. ${workspaceRoot} actually got the value of the first folder on the VS code folders list. So in order to get to all of its siblings folders one needs to add the setting you proposed. One issue I noticed, which is not related to the original issue: Whenever I hit control and point the mouse to a symbol, this extension is running cscope in the background. The problem is that this happens a lot and cscope processes start to accumulate and load the system and they keep running in the background... Is there something that can be set to prevent it?

xulion commented 2 years ago

I tried adding more folders it seems working just fine. like

    "scope4code.sourceCodePaths": [
        "${workspaceRoot}/./",
        "${workspaceRoot}/../folder_1",
        "${workspaceRoot}/../folder_2",
        "${workspaceRoot}/../folder_3",
    ],

one catch here is that you have to restart the vscode or reload the extension because the setting is loaded during launch. updating setting would not trigger reload.

regarding to what you mentioned, I do noticed that. however I don't think there is anything I can do because the extension just provided the implementation of the provider. vscode is the one to call the functions.

arnonshp commented 2 years ago

If that's the case, then I'll have to disable/remove this extension, as it slows down my development system. I believe that extensions should have control on when and on which conditions they are invoked. In case you do come up with a fix for this issue, do let me know and I'll be glad to reinstall this extension again.

xulion commented 2 years ago

As I mentioned earlier, vscode is calling the extension and the only information it provided is the location of the file and the text. there is nothing as an extension can do to know if it supposed to run or not.

If you don't like it you can disable following code which would eliminate the issue but also you would not be able to ctr+click to jump to the definition anymore.

        context.subscriptions.push(vscode.languages.registerReferenceProvider(["cpp", "c"], new RefProvider(executor)));
        context.subscriptions.push(vscode.languages.registerDefinitionProvider(['cpp', 'c'], new DefinitionProvider(executor)));
arnonshp commented 2 years ago

I'm not an extension developer but I guess the extension "subscribes" on certain VS code "events" in order to get those calls. So it would be better to let the user control (via extension setting) whether the cscope would be invoked via mouse hover/click on a symbol in the editor or an explicit command to the extension (Ctrl+Shift+P and choosing "Cscope: Find functions calling this function" or any other Cscope commands exposed by this extension). In addition, it should be the extension's responsibility to make sure the cscope process it has invoked does not remain running after providing the results.

xulion commented 2 years ago

Unfortunately that's not how vscode extension works. Like the code I show above the extension just tell vs code "Hey I have a provider knows how to find definition and reference, here is the instance of it". And whenever vscode decides it wants the links it would call the function provided by the provider. In my cases I do notice that when you press ctrl while hover over a text vscode will call the provider interface.

In future release I can add more settings to disable provide registration. But as I mentioned above once disabled the ctrl click won't be able to bring you to the definition anymore.

PranavKumar-15032001 commented 1 year ago

If that's the case, then I'll have to disable/remove this extension, as it slows down my development system. I believe that extensions should have control on when and on which conditions they are invoked. In case you do come up with a fix for this issue, do let me know and I'll be glad to reinstall this extension again.

Please remove the scope files from the file watcher. This is what worked for, navigate to the workspace settings, and add the path of cscope db or a generic cscope path.

{
...,
 "files.watcherExclude": {
  "**/csope*": true,
 }
}