8000 feat: Emit many common local types (#24) · sourcegraph/scip-python@129a607 · GitHub
[go: up one dir, main page]

Skip to content

Commit 129a607

Browse files
authored
feat: Emit many common local types (#24)
This is the first pass at something that actually provides useful information within a local repository.
1 parent feca4ee commit 129a607

File tree

48 files changed

+1905
-5062
lines changed

Some content is hidden

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

48 files changed

+1905
-5062
lines changed

.github/workflows/release-lsif.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: release-lsif
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
8+
jobs:
9+
release-image:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: actions/setup-node@v2
14+
with:
15+
node-version: 16
16+
registry-url: 'https://registry.npmjs.org'
17+
- run: |
18+
cd ./packages/pyright-lsif/
19+
npm install .
20+
npm run build
21+
npm publish --access public
22+
env:
23+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
24+
- run: echo "PATCH=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
25+
- run: echo "MINOR=${PATCH%.*}" >> $GITHUB_ENV
26+
- run: echo "MAJOR=${MINOR%.*}" >> $GITHUB_ENV

README.md

Lines changed: 20 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,29 @@
1-
![Pyright](/docs/img/PyrightLarge.png)
1+
# lsif-python
22

3-
# Static type checker for Python
3+
Sourcegraph fork of [pyright](https://github.com/microsoft/pyright) focused on generating LSIF for python projects.
44

5-
### Speed
6-
Pyright is a fast type checker meant for large Python source bases. It can run in a “watch” mode and performs fast incremental updates when files are modified.
5+
Project is primarily an addition to Pyright. At this time, there are no substantial changes to the `pyright` library.
76

8-
### Configurability
9-
Pyright supports [configuration files](/docs/configuration.md) that provide granular control over settings. Different “execution environments” can be associated with subdirectories within a source base. Each environment can specify different module search paths, python language versions, and platform targets.
7+
## Pre-requisites
108

11-
### Type Checking Features
12-
* [PEP 484](https://www.python.org/dev/peps/pep-0484/) type hints including generics
13-
* [PEP 487](https://www.python.org/dev/peps/pep-0487/) simpler customization of class creation
14-
* [PEP 526](https://www.python.org/dev/peps/pep-0526/) syntax for variable annotations
15-
* [PEP 544](https://www.python.org/dev/peps/pep-0544/) structural subtyping
16-
* [PEP 561](https://www.python.org/dev/peps/pep-0561/) distributing and packaging type information
17-
* [PEP 563](https://www.python.org/dev/peps/pep-0563/) postponed evaluation of annotations
18-
* [PEP 570](https://www.python.org/dev/peps/pep-0570/) position-only parameters
19-
* [PEP 585](https://www.python.org/dev/peps/pep-0585/) type hinting generics in standard collections
20-
* [PEP 586](https://www.python.org/dev/peps/pep-0586/) literal types
21-
* [PEP 589](https://www.python.org/dev/peps/pep-0589/) typed dictionaries
22-
* [PEP 591](https://www.python.org/dev/peps/pep-0591/) final qualifier
23-
* [PEP 593](https://www.python.org/dev/peps/pep-0593/) flexible variable annotations
24-
* [PEP 604](https://www.python.org/dev/peps/pep-0604/) complementary syntax for unions
25-
* [PEP 612](https://www.python.org/dev/peps/pep-0612/) parameter specification variables
26-
* [PEP 613](https://www.python.org/dev/peps/pep-0613/) explicit type aliases
27-
* [PEP 635](https://www.python.org/dev/peps/pep-0635/) structural pattern matching
28-
* [PEP 646](https://www.python.org/dev/peps/pep-0646/) variadic generics
29-
* [PEP 647](https://www.python.org/dev/peps/pep-0647/) user-defined type guards
30-
* [PEP 655](https://www.python.org/dev/peps/pep-0655/) required typed dictionary items
31-
* [PEP 673](https://www.python.org/dev/peps/pep-0673/) Self type
32-
* [PEP 675](https://www.python.org/dev/peps/pep-0675/) arbitrary literal strings
33-
* [PEP 681](https://www.python.org/dev/peps/pep-0681/) dataclass transform
34-
* Type inference for function return values, instance variables, class variables, and globals
35-
* Type guards that understand conditional code flow constructs like if/else statements
9+
```
10+
$ # Install and add `lsif-typed` to your path and/or project
11+
$ curl -Lo lsif-typed https://github.com/sourcegraph/lsif-typescript/releases/download/v0.1.8/lsif-typed && chmod +x lsif-typed
12+
```
3613

37-
### VS Code Integration
38-
Pyright ships as both a command-line tool and a VS Code extension that provides many powerful features that help improve programming efficiency.
14+
## Usage
3915

40-
### VS Code Language Features
41-
The VS Code extension supports many time-saving language features including:
16+
```
17+
$ npm install @sourcegraph/lsif-python
4218
43-
* Intelligent type completion of keywords, symbols, and import names appears when editing
44-
* Import statements are automatically inserted when necessary for type completions
45-
* Signature completion tips help when filling in arguments for a call
46-
* Hover over symbols to provide type information and doc strings
47-
* Find Definitions to quickly go to the location of a symbol’s definition
48-
* Find References to find all references to a symbol within a code base
49-
* Rename Symbol to rename all references to a symbol within a code base
50-
* Find Symbols within the current document or within the entire workspace
51-
* View call hierarchy information — calls made within a function and places where a function is called
52-
* Organize Imports command for automatically ordering imports according to PEP8 rules
53-
* Type stub generation for third-party libraries
19+
$ # Activate your virtual environment before running
20+
$ lsif-python index . --projectName $MY_PROJECT
5421
55-
### Built-in Type Stubs
56-
Pyright includes a recent copy of the stdlib type stubs from [Typeshed](https://github.com/python/typeshed). It can be configured to use another (perhaps more recent or modified) copy of the Typeshed type stubs. Of course, it also works with custom type stub files that are part of your project.
22+
$ # Transform lsif-python output to traditional LSIF format
23+
$ # (at some point, this step will be removed)
24+
$ lsif-typed dump.lsif-typed > dump.lsif
5725
58-
### Command-line Tool or Visual Studio Code Extension
59-
Pyright includes both a [command-line tool](/docs/command-line.md) and an [extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-pyright.pyright) that implements the [Language Server Protocol](https://microsoft.github.io/language-server-protocol/).
60-
61-
For rich Python editing and debugging capabilities with Visual Studio Code, be sure to also install the official [Microsoft Python extension for Visual Studio Code](https://marketplace.visualstudio.com/itemdetails?itemName=ms-python.python) as Pyright only provides syntax and type checking.
62-
63-
64-
## Installation
65-
### VS Code Extension
66-
For most VS Code users, we recommend using the Pylance extension rather than Pyright. Pylance incorporates the Pyright type checker but features additional capabilities such as IntelliCode and semantic token highlighting. You can install the latest-published version of the Pylance VS Code extension directly from VS Code. Simply open the extensions panel and search for “Pylance”.
67-
68-
### Vim
69-
Vim/neovim users can install [coc-pyright](https://github.com/fannheyward/coc-pyright), the Pyright extension for coc.nvim.
70-
71-
Alternatively, [ALE](https://github.com/dense-analysis/ale) will automatically check your code with Pyright, without requiring any additional configuration.
72-
73-
### Sublime Text
74-
Sublime text users can install the [LSP-pyright](https://github.com/sublimelsp/LSP-pyright) plugin from [package control](https://packagecontrol.io/packages/LSP-pyright).
75-
76-
### Emacs
77-
Emacs users can install [lsp-mode](https://github.com/emacs-lsp/lsp-mode) that includes [lsp-pyright](https://github.com/emacs-lsp/lsp-pyright).
78-
To activate the pyright extension follow the instructions in the [docs](https://emacs-lsp.github.io/lsp-pyright/).
79-
80-
### Command-line
81-
A [community-maintained](https://github.com/RobertCraigie/pyright-python) Python package by the name of “pyright” is available on pypi and conda-forge. This package will automatically install node (which Pyright requires) and keep Pyright up to date.
82-
83-
`pip install pyright`
84-
85-
or
86-
87-
`conda install pyright`
88-
89-
Once installed, you can run the tool from the command line as follows:
90-
`pyright <options>`
91-
92-
93-
Alternatively, you can install the command-line version of Pyright directly from npm, which is part of node. If you don't have a recent version of node on your system, install that first from [nodejs.org](https://nodejs.org).
94-
95-
To install pyright globally:
96-
`npm install -g pyright`
97-
98-
On MacOS or Linux, sudo is required to install globally:
99-
`sudo npm install -g pyright`
100-
101-
To update to the latest version:
102-
`sudo npm update -g pyright`
103-
104-
105-
## Documentation
106-
* [Getting Started with Type Checking](/docs/getting-started.md)
107-
* [Type Concepts](/docs/type-concepts.md)
108-
* [Continuous Integration (CI)](/docs/ci-integration.md)
109-
* [Command-line Options](/docs/command-line.md)
110-
* [Configuration](/docs/configuration.md)
111-
* [Settings](/docs/settings.md)
112-
* [Comments](/docs/comments.md)
113-
* [Type Inference](/docs/type-inference.md)
114-
* [Import Resolution](/docs/import-resolution.md)
115-
* [Extending Builtins](/docs/builtins.md)
116-
* [Type Stubs](/docs/type-stubs.md)
117-
* [Types in Libraries](/docs/typed-libraries.md)
118-
* [Commands](/docs/commands.md)
119-
* [Building & Debugging](/docs/build-debug.md)
120-
* [Pyright Internals](/docs/internals.md)
121-
122-
For additional information about Python static typing, refer to this community-maintained [Python Type School](https://github.com/python/typing/discussions).
123-
124-
## Limitations
125-
Pyright provides support for Python 3.0 and newer. There are no plans to support older versions.
126-
127-
128-
## Community
129-
Do you have questions about Pyright or Python type annotations in general? Post your questions in [the discussion section](https://github.com/microsoft/pyright/discussions).
130-
131-
If you would like to report a bug or request an enhancement, file a new issue in either the [pyright](https://github.com/microsoft/pyright/issues) or [pylance-release](https://github.com/microsoft/pylance-release/issues) issue tracker. In general, core type checking functionality is associated with Pyright while language service functionality is associated with Pylance, but the same contributors monitor both repos. For best results, provide the information requested in the issue template.
132-
133-
134-
## FAQ
135-
**Q:** What is the difference between Pyright and [Pylance](https://github.com/microsoft/pylance-release)?
136-
137-
**A:** Pyright is an open-source Python type checker and language server. Pylance leverages Pyright’s functionality with additional features, some of which are not open-sourced.
138-
139-
**Q:** What is the long-term plan for Pyright?
140-
141-
**A:** Pyright is an officially-supported Microsoft type checker for Python. It will continue to be developed and maintained as an open-source project under its original MIT license terms. The Pyright extension for VS Code is a reference implementation and is not guaranteed to be fully functional or maintained long-term.
142-
143-
144-
## Contributing
145-
146-
This project welcomes contributions and suggestions. For feature and complex bug fix contributions, it is recommended that you first discuss the proposed change with Pyright’s maintainers before submitting the pull request. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
147-
148-
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
149-
150-
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
26+
$ # Make sure to point towards the sourcegraph instance you're interested in uploading to.
27+
$ # more information at https://github.com/sourcegraph/src-cli
28+
$ src lsif upload
29+
```

packages/pyright-internal/src/analyzer/typeStubWriter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ export class TypeStubWriter extends ParseTreeWalker {
148148
private _classNestCount = 0;
149149
private _functionNestCount = 0;
150150
private _ifNestCount = 0;
151-
protected _emittedSuite = false;
152-
protected _emitDocString = true;
151+
private _emittedSuite = false;
152+
private _emitDocString = true;
153153
private _trackedImportAs = new Map<string, TrackedImportAs>();
154154
private _trackedImportFrom = new Map<string, TrackedImportFrom>();
155155
private _accessedImportedSymbols = new Map<string, boolean>();
156156

157-
constructor(private _stubPath: string, private _sourceFile: SourceFile, protected _evaluator: TypeEvaluator) {
157+
constructor(private _stubPath: string, private _sourceFile: SourceFile, private _evaluator: TypeEvaluator) {
158158
super();
159159

160160
// As a heuristic, we'll include all of the import statements

packages/pyright-lsif/TODO.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
- [ ] should `src` be included in the path:
2+
3+
```
4+
# definition sam 87712958455b90fe8d0fb1a0fc110b41d6c3a361 `src.sam`/__init__:
5+
6+
vs
7+
8+
# definition sam 87712958455b90fe8d0fb1a0fc110b41d6c3a361 sam/__init__:
9+
```
10+
11+
It's weird that you'd get different symbols depending on where you index from.
12+
ALSO: that can't be referenced externally RIP

packages/pyright-lsif/development.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Development
2+
3+
## TJ's Workflow
4+
5+
(This is just a rough draft, but if anyone else wants to run, you can basically do this as well)
6+
7+
8+
Get the project building (leave this running)
9+
10+
```
11+
# In one terminal
12+
$ npm run watch
13+
```
14+
15+
Then, you can just run stuff with the index manually
16+
17+
```
18+
$ node ./index $ARGS
19+
```
20+
21+
OR
22+
23+
```
24+
$ nodemon --watch ./dist/lsif-pyright.js --exec '...'
25+
```
26+
27+
This way you can run every time you update the project. For some reason jest is
28+
*painfully* slow. I literally cannot run jest tests. Instead I run the snapshots
29+
with `nodemon` and then check the diffs afterwards

0 commit comments

Comments
 (0)
0