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

Update to public release #24

Merged
merged 52 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
64e618d
use get_global_offset_from_line and fix returned locations
Mar 22, 2023
8b18efd
Merge pull request #1 from crytic/fix-lsp-hooks
broccolirob Mar 22, 2023
f17722f
Add go to implementation function
Apr 26, 2023
755580e
Merge pull request #2 from crytic/go-to-impl
broccolirob Apr 27, 2023
6525001
Raise polling interval so workspace isn't constantly refreshing
May 1, 2023
d5df277
Merge pull request #6 from crytic/polling-increase
broccolirob May 1, 2023
d69959c
Use `pyproject.toml` instead of `setup.py`
frabert Mar 14, 2024
a509f63
Merge pull request #9 from crytic/frabert/migrate-to-pyproject
frabert Mar 20, 2024
8d7e188
Migrate to `pygls`
frabert Mar 19, 2024
16b17bf
Improve some request handlers
frabert Mar 20, 2024
ded0352
Update `semantic-version`
frabert Mar 21, 2024
91c7335
Refactor refresh logic
frabert Mar 21, 2024
550346d
Remove unused variables
frabert Mar 22, 2024
ab5d5b6
Allow requests to be served before compilation is complete
frabert Mar 22, 2024
548f856
Factor out loading detector classes
frabert Mar 22, 2024
7e35647
Factor out code that doesn't depend on loop variables
frabert Mar 25, 2024
de95d1e
Extract common functionality
frabert Mar 25, 2024
dd31bd7
Fix that sometimes the ending character would be `-1`
frabert Mar 25, 2024
8c78e5d
Add util to get `Range` from `Source`
frabert Mar 26, 2024
ed6596d
Add utility method to get the name of functions
frabert Mar 26, 2024
d2cd166
Add utility typedefs
frabert Mar 27, 2024
93117d4
Implement "prepare call hierarchy"
frabert Mar 27, 2024
8f51571
Implement "get incoming calls"
frabert Mar 27, 2024
22d8ccd
Implement "get outgoing calls"
frabert Mar 27, 2024
7e50217
Factor out common functionality
frabert Mar 29, 2024
cae9607
Implement type hierarchy
frabert Mar 29, 2024
deeb067
Extract common functionality to separate module
frabert Apr 1, 2024
a552820
Extract goto-def/impl/ref to separate module
frabert Apr 1, 2024
f5234c5
Extract call hierarchy to separate module
frabert Apr 1, 2024
5e15787
Extract type hierarchy to separate module
frabert Apr 1, 2024
6b6fc93
Forward log messages to clients
frabert Apr 2, 2024
687b4d4
Use a single Slither object for each workspace
frabert Apr 2, 2024
c914576
Making an intermediate copy of the analyses is not necessary anymore
frabert Apr 2, 2024
5f336ed
Now we can remove this hack
frabert Apr 3, 2024
605e026
Add command to refresh folders
frabert Apr 4, 2024
b6f265c
Remove unused commands and types
frabert Apr 4, 2024
135472c
Update README
frabert Apr 4, 2024
3bca8d5
Add brief guide on how to add features
frabert Apr 4, 2024
7147072
Bump `slither-analyzer` dependency version
frabert Apr 8, 2024
4f66e4d
Show function ids as inlays next to definitions
frabert Apr 4, 2024
cfcfef0
Allow navigation using VSCode breadcrumbs
frabert Apr 4, 2024
8af2e2c
Add CodeLens to show SlithIR of functions
frabert Apr 8, 2024
05c97e8
Populate pyproject fields
frabert Apr 9, 2024
89aec95
Set up linting CI checks
frabert Apr 9, 2024
1ae4b4e
Add pip-audit CI
frabert Apr 9, 2024
1d92eed
Add black CI
frabert Apr 9, 2024
89a7a60
Fix typo
frabert Apr 9, 2024
0c91850
Fix Python version parsing issue
frabert Apr 9, 2024
28ece24
Remove old tests
frabert Apr 9, 2024
b972041
Format
frabert Apr 9, 2024
b53791e
Fix pylint
frabert Apr 9, 2024
bccb1e4
Add publish CI
frabert Apr 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/black.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
name: Run black

defaults:
run:
# To load bashrc
shell: bash -ieo pipefail {0}

on:
pull_request:
branches: [main, dev]
paths:
- "**/*.py"
schedule:
# run CI every day even if no PRs/merges occur
- cron: '0 12 * * *'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: Black
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
fetch-depth: 0

- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install dependencies
run: |
mkdir -p .github/linters
cp pyproject.toml .github/linters

- name: Black
uses: super-linter/super-linter/[email protected]
if: always()
env:
# run linter on everything to catch preexisting problems
VALIDATE_ALL_CODEBASE: true
DEFAULT_BRANCH: master
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Run only black
VALIDATE_PYTHON_BLACK: true
PYTHON_BLACK_CONFIG_FILE: pyproject.toml
FILTER_REGEX_EXCLUDE: .*tests/.*.(json|zip|sol)
32 changes: 32 additions & 0 deletions .github/workflows/matchers/pylint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"problemMatcher": [
{
"owner": "pylint-error",
"severity": "error",
"pattern": [
{
"regexp": "^(.+):(\\d+):(\\d+):\\s(([EF]\\d{4}):\\s.+)$",
"file": 1,
"line": 2,
"column": 3,
"message": 4,
"code": 5
}
]
},
{
"owner": "pylint-warning",
"severity": "warning",
"pattern": [
{
"regexp": "^(.+):(\\d+):(\\d+):\\s(([CRW]\\d{4}):\\s.+)$",
"file": 1,
"line": 2,
"column": 3,
"message": 4,
"code": 5
}
]
}
]
}
39 changes: 39 additions & 0 deletions .github/workflows/pip-audit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: pip-audit

on:
push:
branches: [ dev, main ]
pull_request:
branches: [ dev, main ]
schedule: [ cron: "0 7 * * 2" ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
audit:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install Slither
run: |
python -m venv /tmp/pip-audit-env
source /tmp/pip-audit-env/bin/activate

python -m pip install --upgrade pip setuptools wheel
python -m pip install .

- name: Run pip-audit
uses: pypa/[email protected]
with:
virtual-environment: /tmp/pip-audit-env
53 changes: 53 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Publish to PyPI

on:
release:
types: [published]

jobs:
build-release:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Build distributions
run: |
python -m pip install --upgrade pip
python -m pip install build
python -m build
- name: Upload distributions
uses: actions/upload-artifact@v4
with:
name: slither-lsp-dists
path: dist/

publish:
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write # For trusted publishing + codesigning.
contents: write # For attaching signing artifacts to the release.
needs:
- build-release
steps:
- name: fetch dists
uses: actions/download-artifact@v4
with:
name: slither-lsp-dists
path: dist/

- name: publish
uses: pypa/[email protected]

- name: sign
uses: sigstore/[email protected]
with:
inputs: ./dist/*.tar.gz ./dist/*.whl
release-signing-artifacts: true
60 changes: 60 additions & 0 deletions .github/workflows/pylint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
name: Run pylint

defaults:
run:
# To load bashrc
shell: bash -ieo pipefail {0}

on:
pull_request:
branches: [main, dev]
paths:
- "**/*.py"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: Lint Code Base
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
fetch-depth: 0

- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install dependencies
run: |
mkdir -p .github/linters
cp pyproject.toml .github/linters
pip install .

- name: Register pylint problem matcher
run: |
echo "::add-matcher::.github/workflows/matchers/pylint.json"

- name: Pylint
uses: super-linter/super-linter/[email protected]
if: always()
env:
# Run linters only on new files for pylint to speed up the CI
VALIDATE_ALL_CODEBASE: false
# Compare against the base branch
# This is only accessible on PR
DEFAULT_BRANCH: ${{ github.base_ref }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Run only pylint
VALIDATE_PYTHON: true
VALIDATE_PYTHON_PYLINT: true
PYTHON_PYLINT_CONFIG_FILE: pyproject.toml
FILTER_REGEX_EXCLUDE: .*tests/.*.(json|zip|sol)
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
# Slither Language Server Protocol
# Slither Language Server

## How to install

Run the following command from the project root directory (preferably inside a Python virtual environment):

python -m pip install .

## Features
* TODO

* Go to implementations/definitions
* Find all references
* Show call hierarchy
* Show type hierarchy
* View and filter detector results

## Adding new features

New request handlers should be registered in the [constructor of `SlitherServer`](https://github.com/crytic/slither-lsp/blob/4e951da5244b15b69a5cbf4ce2444f205a0d0417/slither_lsp/app/slither_server.py#L120). Please note that in order to keep the conceptual load to a minimum, handlers should not be declared directly in the `SlitherServer` class itself. Instead, related handlers should be declared in a separate module. See [`goto_def_impl_refs.py`](https://github.com/crytic/slither-lsp/blob/c914576b74f748f69738a0a7a38ee6d53bfd1614/slither_lsp/app/request_handlers/goto_def_impl_refs.py) as an example.

The Slither Language Server uses [`pygls`](https://pygls.readthedocs.io/en/latest/index.html) as the LSP implementation, and you should refer to its documentation when writing new handlers.

If you're adding an handler for a standard LSP feature, there will be no need to do anything on the VSCode extension side: VSCode will automatically hook its commands to use the provided feature.

If, on the other hand, the feature you're trying to add does not map to a standard LSP feature, you will need to register a custom handler. See [`$/slither/analyze`](https://github.com/crytic/slither-lsp/blob/4e951da5244b15b69a5cbf4ce2444f205a0d0417/slither_lsp/app/slither_server.py#L117) as an example: note how each request name is prefixed with `$/slither/`. You will need to manually send request from the VSCode extension in order to trigger these handlers.
55 changes: 52 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,61 @@
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "slither-lsp"
description = "Language Server powered by the Slither static analyzer"
version = "0.0.1"
readme = "README.md"
dependencies = [
"slither-analyzer>=0.10.2",
"semantic-version>=2.10.0",
"pygls>=1.3.0"
]
classifiers = [
"License :: OSI Approved :: GNU Affero General Public License v3",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Security",
]
requires-python = ">=3.10"

[[project.authors]]
name = "Trail of Bits"
email = "[email protected]"

[project.license]
file = "LICENSE"

[project.urls]
Repository = "https://github.com/crytic/slither-lsp"
Issues = "https://github.com/crytic/slither-lsp/issues"

[project.scripts]
slither-lsp = "slither_lsp.__main__:main"

# Pylint settings

[tool.pylint.messages_control]
max-line-length = 120

disable = """
import-outside-toplevel,
missing-module-docstring,
useless-return,
duplicate-code
missing-class-docstring,
missing-function-docstring,
unnecessary-lambda,
cyclic-import,
line-too-long,
invalid-name,
fixme,
too-many-return-statements,
too-many-ancestors,
logging-fstring-interpolation,
logging-not-lazy,
duplicate-code,
import-error,
unsubscriptable-object,
unnecessary-lambda-assignment,
too-few-public-methods,
too-many-instance-attributes
"""
24 changes: 0 additions & 24 deletions setup.py

This file was deleted.

Loading