Start work on Python support
This commit is contained in:
parent
dc8d5f4ae3
commit
34351c0a51
7 changed files with 163 additions and 0 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
@ -5277,6 +5277,16 @@ dependencies = [
|
||||||
"tree-sitter",
|
"tree-sitter",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tree-sitter-python"
|
||||||
|
version = "0.20.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e0d315475c65416274539dd1db9fa2de94918a6ef399dc1287be7cb7bc83dd6d"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"tree-sitter",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tree-sitter-rust"
|
name = "tree-sitter-rust"
|
||||||
version = "0.20.1"
|
version = "0.20.1"
|
||||||
|
@ -6030,6 +6040,7 @@ dependencies = [
|
||||||
"tree-sitter-go",
|
"tree-sitter-go",
|
||||||
"tree-sitter-json 0.20.0",
|
"tree-sitter-json 0.20.0",
|
||||||
"tree-sitter-markdown",
|
"tree-sitter-markdown",
|
||||||
|
"tree-sitter-python",
|
||||||
"tree-sitter-rust",
|
"tree-sitter-rust",
|
||||||
"tree-sitter-toml",
|
"tree-sitter-toml",
|
||||||
"tree-sitter-typescript",
|
"tree-sitter-typescript",
|
||||||
|
|
|
@ -94,6 +94,7 @@ tree-sitter-go = { git = "https://github.com/tree-sitter/tree-sitter-go", rev =
|
||||||
tree-sitter-json = { git = "https://github.com/tree-sitter/tree-sitter-json", rev = "137e1ce6a02698fc246cdb9c6b886ed1de9a1ed8" }
|
tree-sitter-json = { git = "https://github.com/tree-sitter/tree-sitter-json", rev = "137e1ce6a02698fc246cdb9c6b886ed1de9a1ed8" }
|
||||||
tree-sitter-rust = "0.20.1"
|
tree-sitter-rust = "0.20.1"
|
||||||
tree-sitter-markdown = { git = "https://github.com/MDeiml/tree-sitter-markdown", rev = "330ecab87a3e3a7211ac69bbadc19eabecdb1cca" }
|
tree-sitter-markdown = { git = "https://github.com/MDeiml/tree-sitter-markdown", rev = "330ecab87a3e3a7211ac69bbadc19eabecdb1cca" }
|
||||||
|
tree-sitter-python = "0.20.0"
|
||||||
tree-sitter-toml = { git = "https://github.com/tree-sitter/tree-sitter-toml", rev = "342d9be207c2dba869b9967124c679b5e6fd0ebe" }
|
tree-sitter-toml = { git = "https://github.com/tree-sitter/tree-sitter-toml", rev = "342d9be207c2dba869b9967124c679b5e6fd0ebe" }
|
||||||
tree-sitter-typescript = "0.20.1"
|
tree-sitter-typescript = "0.20.1"
|
||||||
url = "2.2"
|
url = "2.2"
|
||||||
|
|
|
@ -43,6 +43,11 @@ pub fn build_language_registry(login_shell_env_loaded: Task<()>) -> LanguageRegi
|
||||||
tree_sitter_markdown::language(),
|
tree_sitter_markdown::language(),
|
||||||
None, //
|
None, //
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"python",
|
||||||
|
tree_sitter_python::language(),
|
||||||
|
None, //
|
||||||
|
),
|
||||||
(
|
(
|
||||||
"rust",
|
"rust",
|
||||||
tree_sitter_rust::language(),
|
tree_sitter_rust::language(),
|
||||||
|
|
11
crates/zed/src/languages/python/config.toml
Normal file
11
crates/zed/src/languages/python/config.toml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
name = "Python"
|
||||||
|
path_suffixes = ["py"]
|
||||||
|
line_comment = "# "
|
||||||
|
autoclose_before = ";:.,=}])>"
|
||||||
|
brackets = [
|
||||||
|
{ start = "{", end = "}", close = true, newline = true },
|
||||||
|
{ start = "[", end = "]", close = true, newline = true },
|
||||||
|
{ start = "(", end = ")", close = true, newline = true },
|
||||||
|
{ start = "\"", end = "\"", close = true, newline = false },
|
||||||
|
{ start = "'", end = "'", close = false, newline = false },
|
||||||
|
]
|
125
crates/zed/src/languages/python/highlights.scm
Normal file
125
crates/zed/src/languages/python/highlights.scm
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
(attribute attribute: (identifier) @property)
|
||||||
|
(type (identifier) @type)
|
||||||
|
|
||||||
|
; Function calls
|
||||||
|
|
||||||
|
(decorator) @function
|
||||||
|
|
||||||
|
(call
|
||||||
|
function: (attribute attribute: (identifier) @function.method))
|
||||||
|
(call
|
||||||
|
function: (identifier) @function)
|
||||||
|
|
||||||
|
; Function definitions
|
||||||
|
|
||||||
|
(function_definition
|
||||||
|
name: (identifier) @function)
|
||||||
|
|
||||||
|
; Identifier naming conventions
|
||||||
|
|
||||||
|
((identifier) @constructor
|
||||||
|
(#match? @constructor "^[A-Z]"))
|
||||||
|
|
||||||
|
((identifier) @constant
|
||||||
|
(#match? @constant "^[A-Z][A-Z_]*$"))
|
||||||
|
|
||||||
|
; Builtin functions
|
||||||
|
|
||||||
|
((call
|
||||||
|
function: (identifier) @function.builtin)
|
||||||
|
(#match?
|
||||||
|
@function.builtin
|
||||||
|
"^(abs|all|any|ascii|bin|bool|breakpoint|bytearray|bytes|callable|chr|classmethod|compile|complex|delattr|dict|dir|divmod|enumerate|eval|exec|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|isinstance|issubclass|iter|len|list|locals|map|max|memoryview|min|next|object|oct|open|ord|pow|print|property|range|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|vars|zip|__import__)$"))
|
||||||
|
|
||||||
|
; Literals
|
||||||
|
|
||||||
|
[
|
||||||
|
(none)
|
||||||
|
(true)
|
||||||
|
(false)
|
||||||
|
] @constant.builtin
|
||||||
|
|
||||||
|
[
|
||||||
|
(integer)
|
||||||
|
(float)
|
||||||
|
] @number
|
||||||
|
|
||||||
|
(comment) @comment
|
||||||
|
(string) @string
|
||||||
|
(escape_sequence) @escape
|
||||||
|
|
||||||
|
(interpolation
|
||||||
|
"{" @punctuation.special
|
||||||
|
"}" @punctuation.special) @embedded
|
||||||
|
|
||||||
|
[
|
||||||
|
"-"
|
||||||
|
"-="
|
||||||
|
"!="
|
||||||
|
"*"
|
||||||
|
"**"
|
||||||
|
"**="
|
||||||
|
"*="
|
||||||
|
"/"
|
||||||
|
"//"
|
||||||
|
"//="
|
||||||
|
"/="
|
||||||
|
"&"
|
||||||
|
"%"
|
||||||
|
"%="
|
||||||
|
"^"
|
||||||
|
"+"
|
||||||
|
"->"
|
||||||
|
"+="
|
||||||
|
"<"
|
||||||
|
"<<"
|
||||||
|
"<="
|
||||||
|
"<>"
|
||||||
|
"="
|
||||||
|
":="
|
||||||
|
"=="
|
||||||
|
">"
|
||||||
|
">="
|
||||||
|
">>"
|
||||||
|
"|"
|
||||||
|
"~"
|
||||||
|
"and"
|
||||||
|
"in"
|
||||||
|
"is"
|
||||||
|
"not"
|
||||||
|
"or"
|
||||||
|
] @operator
|
||||||
|
|
||||||
|
[
|
||||||
|
"as"
|
||||||
|
"assert"
|
||||||
|
"async"
|
||||||
|
"await"
|
||||||
|
"break"
|
||||||
|
"class"
|
||||||
|
"continue"
|
||||||
|
"def"
|
||||||
|
"del"
|
||||||
|
"elif"
|
||||||
|
"else"
|
||||||
|
"except"
|
||||||
|
"exec"
|
||||||
|
"finally"
|
||||||
|
"for"
|
||||||
|
"from"
|
||||||
|
"global"
|
||||||
|
"if"
|
||||||
|
"import"
|
||||||
|
"lambda"
|
||||||
|
"nonlocal"
|
||||||
|
"pass"
|
||||||
|
"print"
|
||||||
|
"raise"
|
||||||
|
"return"
|
||||||
|
"try"
|
||||||
|
"while"
|
||||||
|
"with"
|
||||||
|
"yield"
|
||||||
|
"match"
|
||||||
|
"case"
|
||||||
|
] @keyword
|
6
crates/zed/src/languages/python/indents.scm
Normal file
6
crates/zed/src/languages/python/indents.scm
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
(class_definition body: (block)) @indent
|
||||||
|
(function_definition body: (block)) @indent
|
||||||
|
|
||||||
|
(_ "[" "]" @end) @indent
|
||||||
|
(_ "{" "}" @end) @indent
|
||||||
|
(_ "(" ")" @end) @indent
|
|
@ -171,6 +171,10 @@ export function createTheme(
|
||||||
color: sample(ramps.cyan, 0.5),
|
color: sample(ramps.cyan, 0.5),
|
||||||
weight: fontWeights.normal,
|
weight: fontWeights.normal,
|
||||||
},
|
},
|
||||||
|
constructor: {
|
||||||
|
color: sample(ramps.blue, 0.5),
|
||||||
|
weight: fontWeights.normal,
|
||||||
|
},
|
||||||
variant: {
|
variant: {
|
||||||
color: sample(ramps.blue, 0.5),
|
color: sample(ramps.blue, 0.5),
|
||||||
weight: fontWeights.normal,
|
weight: fontWeights.normal,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue