├── LsifDotnet.Benchmark
├── Program.cs
├── LsifDotnet.Benchmark.csproj
└── SelfEmit.cs
├── .dockerignore
├── LsifDotnet.sln.DotSettings
├── .github
└── workflows
│ ├── sourcegraph.yml
│ ├── dotnet.yml
│ ├── Release.yml
│ └── docker-publish.yml
├── LsifDotnet
├── Roslyn
│ ├── IdentifierCollectorFactory.cs
│ └── CSharpIdentifierCollector.cs
├── Dockerfile
├── LsifDotnet.csproj
├── GraphBuilder.cs
├── Program.cs
├── IndexHandler.cs
├── Lsif
│ ├── LsifItem.cs
│ ├── LegacyLsifIndexer.cs
│ └── DataFlowLsifIndexer.cs
└── MarkdownHelper.cs
├── LsifDotnet.Tests
├── LsifDotnet.Tests.csproj
└── KeywordTest.cs
├── tools
└── verify_lsif.py
├── LsifDotnet.sln
├── .gitattributes
├── README.md
├── .gitignore
└── LICENSE
/LsifDotnet.Benchmark/Program.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics;
2 | using BenchmarkDotNet.Running;
3 |
4 | namespace LsifDotnet.Benchmark;
5 |
6 | public class Program
7 | {
8 | public static void Main(string[] args)
9 | {
10 | Trace.Listeners.Add(new ConsoleTraceListener());
11 | var summary = BenchmarkRunner.Run(typeof(Program).Assembly);
12 | }
13 | }
--------------------------------------------------------------------------------
/.dockerignore:
--------------------------------------------------------------------------------
1 | **/.classpath
2 | **/.dockerignore
3 | **/.env
4 | **/.git
5 | **/.gitignore
6 | **/.project
7 | **/.settings
8 | **/.toolstarget
9 | **/.vs
10 | **/.vscode
11 | **/*.*proj.user
12 | **/*.dbmdl
13 | **/*.jfm
14 | **/azds.yaml
15 | **/bin
16 | **/charts
17 | **/docker-compose*
18 | **/Dockerfile*
19 | **/node_modules
20 | **/npm-debug.log
21 | **/obj
22 | **/secrets.dev.yaml
23 | **/values.dev.yaml
24 | LICENSE
25 | README.md
--------------------------------------------------------------------------------
/LsifDotnet.sln.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | True
3 | True
--------------------------------------------------------------------------------
/.github/workflows/sourcegraph.yml:
--------------------------------------------------------------------------------
1 | name: Generate LSIF and push to sourcegraph
2 |
3 | on:
4 | - push
5 |
6 | jobs:
7 | lsif-dotnet:
8 | runs-on: ubuntu-latest
9 | container: ghcr.io/tcz717/lsifdotnet:main
10 | steps:
11 | - uses: actions/checkout@v2.4.0
12 | - name: Restore dependencies
13 | run: dotnet restore
14 | - name: Generate LSIF data
15 | run: /app/lsif-dotnet
16 | - name: Upload LSIF data
17 | run: src lsif upload -github-token=${{ secrets.GITHUB_TOKEN }}
18 |
--------------------------------------------------------------------------------
/LsifDotnet/Roslyn/IdentifierCollectorFactory.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.Logging;
2 |
3 | namespace LsifDotnet.Roslyn;
4 |
5 | public class IdentifierCollectorFactory
6 | {
7 | public CSharpIdentifierCollector CreateInstance()
8 | {
9 | return new CSharpIdentifierCollector(LoggerFactory.CreateLogger());
10 | }
11 |
12 | public IdentifierCollectorFactory(ILoggerFactory loggerFactory)
13 | {
14 | LoggerFactory = loggerFactory;
15 | }
16 |
17 | public ILoggerFactory LoggerFactory { get; }
18 | }
--------------------------------------------------------------------------------
/.github/workflows/dotnet.yml:
--------------------------------------------------------------------------------
1 | name: .NET
2 |
3 | on:
4 | push:
5 | branches: [ main ]
6 | pull_request:
7 | branches: [ main ]
8 |
9 | jobs:
10 | build:
11 |
12 | runs-on: windows-latest
13 |
14 | steps:
15 | - uses: actions/checkout@v2
16 | - name: Setup .NET
17 | uses: actions/setup-dotnet@v1
18 | with:
19 | dotnet-version: 6.0.x
20 | - name: Restore dependencies
21 | run: dotnet restore
22 | - name: Build
23 | run: dotnet build --no-restore
24 | - name: Test
25 | run: dotnet test --no-build --verbosity normal
26 |
--------------------------------------------------------------------------------
/LsifDotnet/Dockerfile:
--------------------------------------------------------------------------------
1 | #See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
2 |
3 | FROM mcr.microsoft.com/dotnet/sdk:6.0 AS base
4 | WORKDIR /app
5 |
6 | FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
7 | ARG VERSION=1.0.0
8 | WORKDIR /src
9 | COPY ["LsifDotnet/LsifDotnet.csproj", "LsifDotnet/"]
10 | RUN dotnet restore "LsifDotnet/LsifDotnet.csproj"
11 | COPY . .
12 | WORKDIR "/src/LsifDotnet"
13 | RUN dotnet publish "LsifDotnet.csproj" -c Release -o /app/publish -p:Version=${VERSION}
14 |
15 | FROM sourcegraph/src-cli:3.34.1 AS src-cli
16 |
17 | FROM base AS final
18 | WORKDIR /app
19 | COPY --from=build /app/publish .
20 | COPY --from=src-cli /usr/bin/src /usr/bin/
--------------------------------------------------------------------------------
/LsifDotnet.Benchmark/LsifDotnet.Benchmark.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net6.0
6 | enable
7 | enable
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/LsifDotnet.Tests/LsifDotnet.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 | enable
6 |
7 | false
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | runtime; build; native; contentfiles; analyzers; buildtransitive
19 | all
20 |
21 |
22 | runtime; build; native; contentfiles; analyzers; buildtransitive
23 | all
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/tools/verify_lsif.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import json
3 |
4 | if __name__ == "__main__":
5 | with open(sys.argv[1], "r") as f:
6 | last_id = 0
7 | total_violation = 0
8 | indexed = set()
9 | for line in f.readlines():
10 | item = json.loads(line)
11 | if item["id"] <= last_id:
12 | print("\033[33mWarn\33[0m: id not increasing:", item["id"])
13 | print("The line is: {line}, last id: {last_id}".format(line=line, last_id=last_id))
14 | total_violation += 1
15 | last_id = item["id"]
16 |
17 | if "inV" in item and not item["inV"] in indexed:
18 | print("\033[31mError\33[0m: inV not indexed:", item["inV"])
19 | print("The line is: {line}, last id: {last_id}".format(line=line, last_id=last_id))
20 | total_violation += 1
21 | if "outV" in item and not item["outV"] in indexed:
22 | print("\033[31mError\33[0m: outV not indexed:", item["outV"])
23 | print("The line is: {line}, last id: {last_id}".format(line=line, last_id=last_id))
24 | total_violation += 1
25 | if "inVs" in item and not indexed.issuperset(item["inVs"]):
26 | print("\033[31mError\33[0m: inVs not indexed:", item["inVs"])
27 | print("The line is: {line}, last id: {last_id}".format(line=line, last_id=last_id))
28 | total_violation += 1
29 |
30 | indexed.add(item["id"])
31 |
32 | print("Total violation:", total_violation)
--------------------------------------------------------------------------------
/LsifDotnet.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.1.32104.313
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LsifDotnet", "LsifDotnet\LsifDotnet.csproj", "{B426E5B4-869F-4B5B-A9DE-DAC355A98301}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LsifDotnet.Tests", "LsifDotnet.Tests\LsifDotnet.Tests.csproj", "{0F90A056-0000-49A9-86F7-99A4F7285C41}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LsifDotnet.Benchmark", "LsifDotnet.Benchmark\LsifDotnet.Benchmark.csproj", "{A428D717-EE2A-490D-BD4A-A902F8C05F13}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Any CPU = Debug|Any CPU
15 | Release|Any CPU = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {B426E5B4-869F-4B5B-A9DE-DAC355A98301}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {B426E5B4-869F-4B5B-A9DE-DAC355A98301}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {B426E5B4-869F-4B5B-A9DE-DAC355A98301}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {B426E5B4-869F-4B5B-A9DE-DAC355A98301}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {0F90A056-0000-49A9-86F7-99A4F7285C41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {0F90A056-0000-49A9-86F7-99A4F7285C41}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {0F90A056-0000-49A9-86F7-99A4F7285C41}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {0F90A056-0000-49A9-86F7-99A4F7285C41}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {A428D717-EE2A-490D-BD4A-A902F8C05F13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {A428D717-EE2A-490D-BD4A-A902F8C05F13}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {A428D717-EE2A-490D-BD4A-A902F8C05F13}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {A428D717-EE2A-490D-BD4A-A902F8C05F13}.Release|Any CPU.Build.0 = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(SolutionProperties) = preSolution
32 | HideSolutionNode = FALSE
33 | EndGlobalSection
34 | GlobalSection(ExtensibilityGlobals) = postSolution
35 | SolutionGuid = {39F2171A-DDEB-4C24-8D7E-43FCB765F1C5}
36 | EndGlobalSection
37 | EndGlobal
38 |
--------------------------------------------------------------------------------
/.github/workflows/Release.yml:
--------------------------------------------------------------------------------
1 | name: .NET Release
2 |
3 | on:
4 | workflow_dispatch:
5 | push:
6 | # Sequence of patterns matched against refs/tags
7 | tags:
8 | - 'v?[0-9]+.[0-9]+.[0-9]+**'
9 |
10 | jobs:
11 | build:
12 | runs-on: ubuntu-latest
13 | strategy:
14 | matrix:
15 | os: [win, linux, osx]
16 |
17 | steps:
18 | - name: Get Version
19 | id: get_version
20 | uses: battila7/get-version-action@v2.2.1
21 | - uses: actions/checkout@v2
22 | - name: Setup .NET
23 | uses: actions/setup-dotnet@v1
24 | with:
25 | dotnet-version: 6.0.x
26 | - name: Restore dependencies
27 | run: dotnet restore
28 | - name: Build
29 | run: dotnet build --no-restore
30 | - name: Test
31 | run: dotnet test --no-build --verbosity normal
32 | - name: Publish
33 | run: dotnet publish -c release -o publish/${{ matrix.os }} --os ${{ matrix.os }} -p:Version=${{ steps.get_version.outputs.version-without-v }} --verbosity normal
34 | - name: Zip Release
35 | # You may pin to the exact commit or the version.
36 | # uses: TheDoctor0/zip-release@591e9b128012d3328db6043d0d0266c3ac27f9b5
37 | uses: TheDoctor0/zip-release@0.6.1
38 | with:
39 | # Filename for archive
40 | filename: lsif-dotnet-${{ matrix.os }}-${{ steps.get_version.outputs.version-without-v }}.zip
41 | # Base path for archive files
42 | path: ${{ matrix.os }}/*
43 | # Working directory before zipping
44 | directory: publish/
45 | - name: GH Release
46 | # You may pin to the exact commit or the version.
47 | # uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5
48 | uses: softprops/action-gh-release@v0.1.14
49 | with:
50 | files: publish/*.zip
51 |
52 | push-nuget:
53 | runs-on: ubuntu-latest
54 | steps:
55 | - name: Get Version
56 | id: get_version
57 | uses: battila7/get-version-action@v2.2.1
58 | - uses: actions/checkout@v2
59 | - name: Setup .NET
60 | uses: actions/setup-dotnet@v1
61 | with:
62 | dotnet-version: 6.0.x
63 | - name: Restore dependencies
64 | run: dotnet restore
65 | - name: Pack
66 | run: dotnet pack -c release -p:Version=${{ steps.get_version.outputs.version-without-v }} -p:PackageId=LsifDotnet --verbosity normal LsifDotnet/LsifDotnet.csproj
67 | - name: Publish Nuget
68 | run: dotnet nuget push LsifDotnet/nupkg/ --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
69 |
--------------------------------------------------------------------------------
/LsifDotnet/LsifDotnet.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net6.0
6 | lsif-dotnet
7 | enable
8 | tcz717
9 | https://github.com/tcz717/LsifDotnet/blob/main/LICENSE
10 | https://github.com/tcz717/LsifDotnet
11 | README.md
12 | https://github.com/tcz717/LsifDotnet
13 | roslyn;lsif;lsif-indexer;lsif-generator;lsif-dump;lsif-dotnet
14 | LICENSE
15 | True
16 | Linux
17 |
18 | True
19 | dotnet-lsif
20 | ./nupkg
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 | True
42 | \
43 |
44 |
45 |
46 |
47 |
48 | True
49 | \
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # LsifDotnet [](https://github.com/tcz717/LsifDotnet/actions/workflows/dotnet.yml)
2 |
3 | Visit https://lsif.dev/ to learn about LSIF.
4 |
5 | Example scenario: [Sourcegraph precise code intelligence](https://docs.sourcegraph.com/code_intelligence/explanations/precise_code_intelligence) ([lsif-dotnet repo](https://sourcegraph.com/github.com/tcz717/LsifDotnet/-/blob/LsifDotnet/Program.cs))
6 |
7 |
8 | Only tested in win platform and don't support `VisualBasic` yet.
9 |
10 | Implmented LSIF data:
11 |
12 | - `textDocument/hover`
13 | - `textDocument/references`
14 | - `textDocument/definition`
15 | - `moniker`
16 |
17 | ### Requirement
18 |
19 | Installed [.net 6.0](https://dotnet.microsoft.com/en-us/download/dotnet/6.0)
20 |
21 | ## Install via nuget
22 | [Package Home](https://www.nuget.org/packages/LsifDotnet/)
23 | ```powershell
24 | dotnet tool install --global LsifDotnet
25 | dotnet lsif
26 | ```
27 |
28 | ### Usage
29 |
30 | ```
31 | PS C:\Downloads\lsif-dotnet-win-0.0.1-beta6\win> .\lsif-dotnet.exe -h
32 | Description:
33 | An indexer that dumps lsif information from dotnet solution.
34 |
35 | Usage:
36 | lsif-dotnet [] [options]
37 |
38 | Arguments:
39 | The solution to be indexed. Default is the only solution file in the current folder.
40 |
41 | Options:
42 | -o, --output