Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# indexing doesn't work properly #62

Open
rodion-m opened this issue May 14, 2024 · 7 comments
Open

C# indexing doesn't work properly #62

rodion-m opened this issue May 14, 2024 · 7 comments

Comments

@rodion-m
Copy link

I've built scip-dotnet from sources, run it on eShop:

dotnet run --project ScipDotnet -- index --working-directory /RiderProjects/eShop

It worked for 20 seconds:

info: ScipDotnet.IndexCommandOptions[0] done: RiderProjects/eShop/index.scip 20s

And then gave the file that contains only "scip-dotnet nuget . . ..." symbols. Like this:

        {
          "Range": [
            73,
            48,
            67
          ],
          "Symbol": "scip-dotnet nuget . . Catalog/CatalogService#GetCatalogTypeAsync().",
          "SymbolRoles": 1,
          "OverrideDocumentation": [],
          "SyntaxKind": 0,
          "Diagnostics": []
        },

What am I doing wrong? I'd like to get all references (usages) for classes and their methods.

@rodion-m
Copy link
Author

rodion-m commented May 14, 2024

@keynmol
Copy link

keynmol commented May 14, 2024

Hello, can you clarify what you mean by

And then gave the file that contains only "scip-dotnet nuget . . ..." symbols

?

I ran the indexer on the project you mentioned (thanks for an open source reproducer), and I can see symbols such as this extracted with references and the rest of the information:

scip-dotnet nuget . . API/CatalogApi#GetImageMimeTypeFromImageFileExtension().

scip-dotnet nuget . . API/CatalogApi#GetImageMimeTypeFromImageFileExtension().(extension)

scip-dotnet nuget . . API/CatalogApi#GetFullPath().

scip-dotnet nuget . . API/CatalogApi#GetFullPath().(contentRootPath)

scip-dotnet nuget . . API/CatalogApi#GetFullPath().(pictureFileName)

The full grammar for reading symbol names is available in the SCIP repository, and the parts you refer to are, specifically:

// <symbol>               ::= <scheme> ' ' <package> ' ' (<descriptor>)+ | 'local ' <local-id>
// <package>              ::= <manager> ' ' <package-name> ' ' <version>
// <scheme>               ::= any UTF-8, escape spaces with double space.

. is used as a placeholder for empty value, where the indexer wasn't able to extract some information. For example in

scip-dotnet nuget . . API/CatalogApi#GetFullPath().(pictureFileName)

scheme = scip-dotnet
package.manager = nuget
package.package-name = .
package.version = .

The rest of the symbol refers to the symbol name.

Not all indexers fill all the package fields, it depends on the completeness of the implementation and the particular project being indexed

@rodion-m
Copy link
Author

Oh, thanks a lot for a fast reaction!
But where are methods references? I thought that I'll be able to reproduce the full call graph from scip file, based on references that it provides.

Let's consider a method Order.AddOrderItem from eShop.Ordering.Domain.AggregatesModel.OrderAggregate.
This is what scip-dotnet gives:

        {
          "Symbol": "scip-dotnet nuget . . OrderAggregate/Order#AddOrderItem().",
          "Documentation": [
            "\u0060\u0060\u0060cs\npublic void Order.AddOrderItem(int productId, string productName, decimal unitPrice, decimal discount, string pictureUrl, [int units = 1])\n\u0060\u0060\u0060"
          ],
          "Relationships": []
        },

So, Relationships is empty. But Rider says that this method has 3 references:
image

Perhaps I'm doing something wrong. If yes, I'll appreciate your help on getting known how to retrieve all references (for AddOrderItem method for example).

Also, I was wondering, is it possible to enable full namespace and full file path for a symbol?

@olafurpg
Copy link
Member

Thank you for reporting! I was able to index the eshop repo and the index seems to be missing many references to global symbols. Steps to reproduce

# clone dotnet/eshop
cd eshop
scip-dotnet index
scip snapshot
open scip-snapshotsrc/HybridApp/MauiProgram.cs

In the screenshot below, you can see the missing references

CleanShot 2024-05-14 at 12 58 02@2x

When indexing, I did get an error about a missing maui-tizen workload

❯ scip-dotnet index eShop.sln
12:57:12 info: ScipDotnet.IndexCommandOptions[0] $ dotnet restore /Users/olafurpg/dev/dotnet/eshop/eShop.sln /p:EnableWindowsTargeting=true
  Determining projects to restore...
/usr/local/share/dotnet/sdk/8.0.100-rc.2.23502.2/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1147: To build this project, the following workloads must be installed: maui-tizen [/Users/olafurpg/dev/dotnet/eshop/tests/ClientApp.UnitTests/ClientApp.UnitTests.csproj]
/usr/local/share/dotnet/sdk/8.0.100-rc.2.23502.2/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1147: To install these workloads, run the following command: dotnet workload restore [/Users/olafurpg/dev/dotnet/eshop/tests/ClientApp.UnitTests/ClientApp.UnitTests.csproj]
12:57:21 info: ScipDotnet.IndexCommandOptions[0] done: /Users/olafurpg/dev/dotnet/eshop/index.scip 9.6s

@rodion-m any idea how to fix that error?

@olafurpg
Copy link
Member

@rodion-m The relationships field is not used to show references. To find references, you need to iterate through all the occurrences of all the documents in the index to find ones with matching symbol

symbol_to_find = "scip-dotnet nuget . . OrderAggregate/Order#AddOrderItem()."
for document in index.documents:
  for occurrence in document.occurrences:
    if occurrence.symbol == symbol_to_find:
      pass # TODO

@rodion-m
Copy link
Author

Thank you for the answer! What about restoring a symbol full namespace?

I suppose that the error is about MAUI that should be installed. Here is an installation guide: https://learn.microsoft.com/en-us/dotnet/maui/get-started/installation?tabs=vswin&view=net-maui-8.0

@olafurpg
Copy link
Member

What about restoring a symbol full namespace?

Can you elaborate what this means? A symbol has several parts:

scip-dotnet nuget . . OrderAggregate/Order#AddOrderItem().
^^^^^^^^^^^  indexer
            ^^^^^ package manager
                  ^ package name ("." is anonymous)
                    ^ package version ("." is anonymous)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ symbol descriptor

If you are referring to the package name/version, scip-dotnet does try to extract it but it may not be working 100% in all cases. We have a test case for this here

// ^^^^^^^^ reference scip-dotnet nuget DiffPlex 1.7.1.0 DiffPlex/

The best way to fix issues in this space is to reproduce then with a test case by writing code in the the "input" project like here https://github.com/sourcegraph/scip-dotnet/blob/main/snapshots/input/syntax/Main/Packages.cs

@linear linear bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants