Skip to content

Commit 3a3ca0c

Browse files
Migrate SCIP code out of sourcegraph/sourcegraph (#1)
* schema: Add protobuf schema from sourcegraph/sourcegraph. * Generate output from protobuf + add brief docs. * Add Go bindings + CLI. * Add GitHub PR template. * ci: Add GitHub Actions for checking validity. * Consolidate language stuff under bindings/. * Run go mod tidy. * Fix typo in GitHub Action name. * Fix bindings generation for TypeScript. * ci: Install toolchains using asdf. * Migrate code for Repro lang to scip repo. * ci: Break out language checks into separate GitHub Actions. * Use Yarn workspaces to unify yarn.lock file * Remove SOC2 mention from the PR template. * Remove PR auditor check to reduce risk of discouraging external contributions * Fix failing TypeScript CI job * Use `git diff --exit-code` to see why the command failed * Fix tree-sitter CI job * This commit should fail in CI * Revert "This commit should fail in CI" * Experiment with reusable GH workflows * Add missing `shell` property * Optimization: skip unnecessary asdf installations * Add shell property, and fix names of jobs * Fix indentation level for `inputs:` * Add missing asdf directory to the PATH * Add asdf binaries to the PATH * Use asdf in protobuf CI job * Add prettier formatting check * Reformat with prettier * Give formatting CI job a proper name * Skip tree-sitter generated files from prettier * Tweak glob patterns for formatting CI check * Don't install docs for Rust * Fix paths for generated files in .gitattributes * Fix incorrect mentions of LSIF to SCIP. * Move reprolang under cmd/tests/. * Add editor-specific directories to .gitignore * Fix Rust check for reprolang move. * Rerun all workflows if any single one changes. * ci: Use local prettier not global. * Fix prettier nonsense. Co-authored-by: Varun Gandhi <[email protected]> Co-authored-by: Ólafur Páll Geirsson <[email protected]>
1 parent 073b0cb commit 3a3ca0c

File tree

102 files changed

+14382
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+14382
-0
lines changed

.gitattributes

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bindings/typescript/scip.ts linguist-generated=true
2+
bindings/go/scip/scip.pb.go linguist-generated=true
3+
bindings/rust/src/scip.rs linguist-generated=true
4+
yarn.lock linguist-generated=true

.github/PULL_REQUEST_TEMPLATE.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
### Test plan

.github/actions/asdf/action.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: asdf
2+
description: Installs system dependencies (Go, Rust, Nodejs) from .tool-versions file
3+
on:
4+
workflow_call:
5+
inputs:
6+
js:
7+
required: false
8+
type: boolean
9+
golang:
10+
required: false
11+
type: boolean
12+
rust:
13+
required: false
14+
type: boolean
15+
runs:
16+
using: 'composite'
17+
steps:
18+
# Avoid using separate GitHub Actions for installing toolchains for
19+
# Go, Rust etc. Maintaining all toolchain versions with asdf using
20+
# a single .tool-versions file is easier.
21+
- name: Install asdf
22+
shell: bash
23+
run: |
24+
set -e
25+
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.10.0 --depth=1
26+
echo $HOME/.asdf/bin >> $GITHUB_PATH
27+
echo $HOME/.asdf/shims >> $GITHUB_PATH
28+
- name: Install JS
29+
if: ${{ inputs.js }}
30+
shell: bash
31+
run: |
32+
asdf plugin-add yarn
33+
asdf install yarn
34+
asdf plugin-add nodejs
35+
asdf install nodejs
36+
- name: Install Rust
37+
if: ${{ inputs.rust }}
38+
shell: bash
39+
run: |
40+
RUST_WITHOUT=rust-docs asdf plugin-add rust https://github.com/asdf-community/asdf-rust.git
41+
asdf install rust
42+
- name: Install Go
43+
if: ${{ inputs.golang }}
44+
shell: bash
45+
run: |
46+
asdf plugin-add golang
47+
asdf install golang

.github/workflows/formatting.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Formatting
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '.github/workflows/**'
7+
- '**.md'
8+
- '**.yml'
9+
- '**.yaml'
10+
- '**.js'
11+
- '**.ts'
12+
13+
jobs:
14+
prettier:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
- run: yarn install
19+
- run: yarn run prettier-check

.github/workflows/golang.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Go
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '.github/workflows/**'
7+
- '**.go'
8+
- '**/go.mod'
9+
- '**/go.sum'
10+
11+
jobs:
12+
check:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
- uses: ./.github/actions/asdf
17+
with:
18+
golang: true
19+
- run: go test ./...

.github/workflows/protobuf.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Protobuf
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '.github/workflows/**'
7+
- 'docs/**'
8+
- 'bindings/**'
9+
- 'scip.proto'
10+
- 'buf**'
11+
12+
jobs:
13+
check:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
- uses: ./.github/actions/asdf
18+
with:
19+
js: true
20+
rust: true
21+
golang: true
22+
- run: ./dev/proto-generate.sh
23+
- run: git diff --exit-code

.github/workflows/reprolang.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Reprolang
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '.github/workflows/**'
7+
- 'reprolang/**'
8+
9+
jobs:
10+
check:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- uses: ./.github/actions/asdf
15+
with:
16+
js: true
17+
- run: ./cmd/tests/reprolang/generate-tree-sitter-parser.sh
18+
- run: git diff --exit-code

.github/workflows/rust.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Rust
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '.github/workflows/**'
7+
- '**.rs'
8+
- '**/Cargo.toml'
9+
- '**/Cargo.lock'
10+
11+
jobs:
12+
check:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
- uses: ./.github/actions/asdf
17+
with:
18+
rust: true
19+
- run: cargo check
20+
working-directory: bindings/rust
21+
- run: cargo check
22+
working-directory: cmd/tests/reprolang

.github/workflows/typescript.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: TypeScript
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '.github/workflows/**'
7+
- '**.ts'
8+
- '**/package.json'
9+
- '**/tsconfig.json'
10+
- '**/yarn.lock'
11+
12+
jobs:
13+
check:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
- uses: ./.github/actions/asdf
18+
with:
19+
js: true
20+
- run: yarn install
21+
- name: Check TypeScript
22+
run: ./node_modules/.bin/tsc -b bindings/typescript

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@
55
*.so
66
*.dylib
77

8+
# Editor directories
9+
.idea/
10+
.vscode/
11+
812
# Test binary, built with `go test -c`
913
*.test
1014

1115
# Output of the go coverage tool, specifically when used with LiteIDE
1216
*.out
1317

18+
**/node_modules/
19+
.bin/
20+
**/target/
21+
1422
# Dependency directories (remove the comment below to include it)
1523
# vendor/

.prettierignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
reprolang/target
2+
reprolang/src/grammar.json
3+
reprolang/src/node-types.json
4+
bindings/typescript
5+
.bin

.prettierrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"semi": false,
3+
"trailingComma": "es5",
4+
"singleQuote": true,
5+
"useTabs": false,
6+
"arrowParens": "avoid"
7+
}

.tool-versions

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
golang 1.18.1
2+
nodejs 16.7.0
3+
shellcheck 0.7.1
4+
yarn 1.22.17
5+
rust 1.60.0

Development.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Developing SCIP
2+
3+
## Project structure
4+
5+
- [bindings/](./bindings/): Contains a mix of generated and hand-written
6+
bindings for different languages.
7+
- [cmd/](./cmd/): CLI for SCIP.
8+
- [cmd/tests/](./cmd/tests/): Test data and packages for SCIP.
9+
- [cmd/tests/reprolang/](./cmd/tests/reprolang/): A verbose, small language
10+
which consists of declarations, references, imports and other minor bits
11+
of functionality, which is used to test the SCIP CLI. The language is
12+
defined using a [tree-sitter grammar](cmd/tests/reprolang/grammar.js).
13+
This functionality not meant for use outside of this repository.
14+
- [docs/](./docs/): Auto-generated documentation.
15+
16+
## Code generation
17+
18+
1. Regenerating definitions after changing the schema in [scip.proto](./scip.proto).
19+
```
20+
./dev/proto-generate.sh
21+
```
22+
2. Regenerating snapshots after making changes to the CLI.
23+
```
24+
go test ./cmd -update-snapshots
25+
```
26+
3. Regenerating parser for Repro after editing its grammar.
27+
```
28+
cd cmd/tests/reprolang
29+
./generate-tree-sitter-parser.sh
30+
```

Readme.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Semantic Code Intelligence Protocol (SCIP)
2+
3+
## Contributing
4+
5+
See [Development.md](./Development.md).
6+
7+
Contributors should abide by the [Sourcegraph Code of Conduct](https://handbook.sourcegraph.com/company-info-and-process/communication/code_of_conduct/).

bindings/go/scip/position.go

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package scip
2+
3+
// Range represents a range between two offset positions.
4+
// NOTE: the github.com/sourcegraph/sourcegraph/lib/codeintel/lsif/protocol package
5+
// contains similarly shaped structs but this one exists primarily to make it
6+
// easier to work with SCIP encoded positions, which have the type []int32
7+
// in Protobuf payloads.
8+
type Range struct {
9+
Start Position
10+
End Position
11+
}
12+
13+
// Position represents an offset position.
14+
type Position struct {
15+
Line int32
16+
Character int32
17+
}
18+
19+
// NewRange converts an SCIP range into `Range`
20+
func NewRange(scipRange []int32) *Range {
21+
var endLine int32
22+
var endCharacter int32
23+
if len(scipRange) == 3 { // single line
24+
endLine = scipRange[0]
25+
endCharacter = scipRange[2]
26+
} else if len(scipRange) == 4 { // multi-line
27+
endLine = scipRange[2]
28+
endCharacter = scipRange[3]
29+
}
30+
return &Range{
31+
Start: Position{
32+
Line: scipRange[0],
33+
Character: scipRange[1],
34+
},
35+
End: Position{
36+
Line: endLine,
37+
Character: endCharacter,
38+
},
39+
}
40+
}
41+
42+
func (r Range) IsSingleLine() bool {
43+
return r.Start.Line == r.End.Line
44+
}
45+
46+
func (r Range) SCIPRange() []int32 {
47+
if r.Start.Line == r.End.Line {
48+
return []int32{r.Start.Line, r.Start.Character, r.End.Character}
49+
}
50+
return []int32{r.Start.Line, r.Start.Character, r.End.Line, r.End.Character}
51+
}

0 commit comments

Comments
 (0)