Skip to content

Commit

Permalink
Adding more feature coverages (#5165)
Browse files Browse the repository at this point in the history
* more examples

* using wrong overload

* covers more features

* covers more features

* covered all editor features

* added header
  • Loading branch information
heejaechang authored Nov 29, 2023
1 parent ae32857 commit 479fdcb
Show file tree
Hide file tree
Showing 22 changed files with 373 additions and 9 deletions.
14 changes: 13 additions & 1 deletion testing/single/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@
"python.analysis.enablePytestSupport": true,
"python.analysis.enablePytestExtra": true,
"python.analysis.inlayHints.pytestParameters": true,
"python.analysis.inlayHints.callArgumentNames": "all",
"python.analysis.inlayHints.functionReturnTypes": true,
"python.analysis.inlayHints.variableTypes": true,
"python.analysis.autoImportCompletions": true,
"python.analysis.indexing": true,
"python.analysis.typeCheckingMode": "basic",
}
"python.analysis.importFormat": "absolute",
"python.analysis.diagnosticSeverityOverrides": {
"reportMissingTypeStubs": "information"
},
// "editor.codeActionsOnSave": { "source.fixAll": true },
// "python.analysis.fixAll": [
// "source.unusedImports",
// "source.convertImportFormat"
// ]
}
1 change: 1 addition & 0 deletions testing/single/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pytest
zope.event
36 changes: 35 additions & 1 deletion testing/single/src/codeaction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# you can trigger quick fix explicitly using `QuickFix` command
# use `command palette` to find the command and its short cut
# since code action usually modify code, make sure `undo` work as expected.

# place cursor on `os` and confirm lightbulb shows up
# and trigger quick fix and confirm `Add 'import os'` is listed
Expand Down Expand Up @@ -54,6 +55,39 @@ class TypeToMove:
# select code between `codeToExtract` and `print(codeToExtract)` and confirm lightbulb shows up
# and trigger quick fix and confirm `extract method` is listed
# execute the code action and confirm it works as expected
# confirm it can be executed through "Refactoring..." menu as well
def function():
codeToExtract = 1
print(codeToExtract)
print(codeToExtract)


# select `1 + 2 + 3` and confirm lightbulb shows up
# and trigger quick fix and confirm `extract variable` is listed
# execute the code action and confirm it works as expected
# confirm it can be executed through "Refactoring..." menu as well
print(1 + 2 + 3)


# place curosr on `userModule` and confirm lightbulb shows up
# and trigger quick fix and confirm `Convert to relative path` is listed
# execute the code action and confirm it works as expected
from lib.userModule import MyType


# place curosr on `mailbox` and confirm lightbulb shows up
# and trigger quick fix and confirm `Rename "...mailbox" to "...mailbox_x"` entry is listed
# execute the code action and confirm it works as expected
import mailbox


# place curosr on `None` and confirm lightbulb shows up
# and trigger quick fix and confirm `Add "Optional" To type annotation` is listed
# execute the code action and confirm it works as expected
def foo(a: int = None) -> int:
return a


# place curosr on `event` and confirm lightbulb shows up
# and trigger quick fix and confirm `Create Type Stub` entry is listed
# execute the code action and confirm it works as expected
import zope.event
36 changes: 34 additions & 2 deletions testing/single/src/completion.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# you can trigger suggestion (completion) explicitly using `Trigger Suggestion` command
# use `command palette` to find the command and its short cut
# also make sure to expand completion item tooltip (>) to see them
from typing import Literal, TypedDict
from typing import Literal, TypedDict, overload


# bring up completion after `os` and confirm tooltip and `os` is added as `auto import`
os
Expand All @@ -11,7 +12,7 @@ class MyDict(TypedDict):
name: str
age: int

a = MyDict()
a = MyDict(name="Hello", age=10)

# bring up typed dict key completion inside of `[]` and confirm `name` and `age` are suggested
a[]
Expand All @@ -26,6 +27,37 @@ class MyDict(TypedDict):
# bring up string literal completion inside of `""` and confirm 2 literals are suggested
e: Literal["Hello", "There"] = ""

# bring up string literal completion between `""` and confirm `"Hello"` is suggested
match e:
case ""

# bring up symbol completion after `My` and confirm tooltip and `MyDict` is suggested
My

# bring up symbol completion after `import` and confirm all top level modules are suggested
import

# bring up symbol completion after `import` and confirm all symbols under pandas
# including sub modules are suggested
from pandas import

from lib.userModule import MyType

# bring up override completion after `me` and confirm `method` is suggested
# commit the completion and confirm all necessary imports are inserted.
class Derived(MyType):
def me


# bring up overload completion after `ha` and confirm `handle` is suggested
class TypeWithOverload:
@overload
def handle(self, a: int) -> str:
return "Hello"

@overload
def ha

# bring up named parameter completion after `sep` and confirm `sep=` is suggested
print("Hello", sep)

21 changes: 21 additions & 0 deletions testing/single/src/diagnostics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# you can trigger diagnostics using `View: Focus Problems`
# use `command palette` to find the command and its short cut
# but that said, it will be automatically triggered and show up as squiggles in editor
# or colored number in file explorer or entries in problems tab.

# import error
import unknownModule

# unknown identifier
unknownIdentifier

# syntax error
:""

# type error
# if you hover your mouse on the error, you should be able to execute code action
# associated with the error explicitly. it can be done from problem tab as well by
# hovering icon on the entry in problem tab.
a: int = "Hello"


27 changes: 27 additions & 0 deletions testing/single/src/documentHighlight.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# you can trigger document highlight using `Trigger Symbol Highlight`
# use `command palette` to find the command and its short cut
# but that said, it will automatically run if you put cursor on top
# of supported symbol

# place cursor on `variable` and confirm all `variable` referenced in the document
# is highlighted
from typing import Literal


variable = "Hello"

print(variable)

# place cursor on `ch` and confirm the same
for ch in variable:
print(ch)


# place cursor on `ConstructorHR` and confirm all references are highlighted
class ConstructorHR:
# place cursor on `__init__` and confirm all references of object creation are highlighted
def __init__(self):
pass

def foo(i: ConstructorHR) -> ConstructorHR:
return ConstructorHR()
21 changes: 21 additions & 0 deletions testing/single/src/documentSymbol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# you can trigger document symbol using `Explorer: Focus on Outline View`
# or `Go to Symbol in Editor ...` commands
# use `command palette` to find the command and its short cut

# confirm the `OUTLINE` view shows symbol hierarchy of the code view
# click entries in the view to make sure correct symbols are highlighted
# and double click to jump to the code

# confirm the `Go to symbol in Editor` also works as expected
class A:
def __init__(self, v: int):
self.v = v

def getValue(self) -> int:
return self.v


def createA(v: int) -> A:
return A(v)

aInstance = createA(10)
3 changes: 3 additions & 0 deletions testing/single/src/folding.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# you can trigger folding range using `Go to next folding range` command
# use `command palette` to find the command and its short cut
# but that said, folding range should automatically run when a file is opened.
from typing import Callable, Type, TypeVar

_T = TypeVar("_T")
Expand Down
23 changes: 23 additions & 0 deletions testing/single/src/formatOnType.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# you can trigger format on type by hitting enter at the end of statement

# place cursor after `:` and hit enter and confirm cursor is placed
# at the expected indentation
for a in range(10):

__break_for_statement_ # its here so that code after this is not recognized as body of the for statement.

# place cursor after `"a"` and hit enter
ch = "a"

# place cursor after `ch:` and hit enter
match ch:
# place cursor after `:` and hit enter
case "a":

__break_for_case_ # its here so that code after this is not recognized as body of the case statement.


if ch == "a":
pass
# type `:` after `else` and see `else` is moved to right position.
else
18 changes: 18 additions & 0 deletions testing/single/src/gotodecl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# you can trigger go to declaration using `Go To Declaration` command
# use `command palette` to find the command and its short cut
# one can also use right click menu to issue the command
from typing import Mapping



# place cursor on `==` and issue go to decl command
# it should go to pyi file.
a = 1 == 1

# place curosr on "os" and issue go to decl command
# it should go to pyi file.
b = "os"

# place curosr on "Mapping" and issue go to decl command
# it should go to pyi file instead of py file.
c: Mapping
19 changes: 19 additions & 0 deletions testing/single/src/gotodef.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# you can trigger go to definition using `Go To Definition` command
# use `command palette` to find the command and its short cut
# one can also use right click menu to issue the command
from typing import Mapping


class ClassWithMagicMethod:
def __lt__(self, v: int) -> bool:
return True


# place cursor on `<` and issue go to def command
a = ClassWithMagicMethod() < 1

# place curosr on "os" and issue go to def command
b = "os"

# place curosr on "Mapping" and issue go to def command
c: Mapping
21 changes: 21 additions & 0 deletions testing/single/src/gototypedef.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# you can trigger go to type definition using `Go To Type Definition` command
# use `command palette` to find the command and its short cut
# one can also use right click menu to issue the command

myVariable: int = 1


# place cursor on `myVariable` and run go to type def
# confirm it goes to the type of the expression (`int` decl in builtin),
# not the variable `myVariable` itself (myVariable: int = 1)
print(myVariable)


class MyType:
name: str

a = MyType()

# place cursor on `name` and run go to type def
# confirm it goes to the type of the member (`str` decl in builtin)
a.name
17 changes: 14 additions & 3 deletions testing/single/src/hover.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

def foo(a: int) -> str:
""" doc comment """
pass
return "hello"

# hover on `foo`` and confirm signature and doc comment
foo()
foo(10)

class MyDict(TypedDict):
name: str
Expand All @@ -21,4 +21,15 @@ class MyDict(TypedDict):
c = "os"

# hover on `typing` and `TypedDict` and confirm it shows tooltip for `typing` and `TypedDict`
d = "typing.TypedDict"
d = "typing.TypedDict"

class MyNumber:
def __init__(self, v: int):
self._value = v

def __add__(self, v: "MyNumber") -> "MyNumber":
return MyNumber(self._value + v._value)


# hover on `+` and confirm it shows tooltip for `__add__`
e = MyNumber(0) + MyNumber(1)
12 changes: 12 additions & 0 deletions testing/single/src/inlayHint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# you can trigger inlay hint by opening a python file

from io import FileIO
from pathlib import Path
from typing import Optional

# confirm inlay return type
def method(a: int, b: str, /, c: Path, *, d: Optional[FileIO] = None):
return a

# confirm inlay variable type and call arguments
var = method(10, "hello", Path("path"), d=None)
8 changes: 7 additions & 1 deletion testing/single/src/lib/userModule.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
from zipfile import Path

from requests import ConnectTimeout


class MyType:
pass
def method(self, v: Path) -> ConnectTimeout:
raise Exception("Hello")
1 change: 1 addition & 0 deletions testing/single/src/mailbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# shadowing stdlib mailbox module
16 changes: 16 additions & 0 deletions testing/single/src/selectionRange.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# you can trigger selection range using `Expand/Shrink Selection`
# use `command palette` to find the command and its short cut
from typing import Literal


def foo(ch: Literal["a", "b", "c"]):
match ch:
case "a":
pass
case "b":
for i in range(10):
# place cursor at `print` and issue `Expand Selection`
# repeat the command and confirm the selection is expanded as expected
print(f"{ch}{i}")
case "c":
pass
Loading

0 comments on commit 479fdcb

Please sign in to comment.