新增語言至 Zed
LSP
Zed 使用 語言伺服器協定 (LSP) 來提供語言支援。這意味著,理論上,我們可以支援任何具有 LSP 伺服器的語言。
語法高亮顯示
定義語法高亮顯示規則
我們使用 tree-sitter 查詢來匹配要高亮顯示的特定屬性。
簡單範例
(property_identifier) @property
const font: FontFamily = {
weight: "normal",
underline: false,
italic: false,
};
匹配屬性識別碼並使用識別碼 @property
高亮顯示它。在上述範例中,weight
、underline
和 italic
將會被高亮顯示。
複雜範例
(_
return_type: (type_annotation
[
(type_identifier) @type.return
(generic_type
name: (type_identifier) @type.return)
]))
function buildDefaultSyntax(colorScheme: Theme): Partial<Syntax> {
// ...
}
匹配函數回傳類型,並使用識別碼 @type.return
高亮顯示該類型。在上述範例中,Partial
將會被高亮顯示。
範例 - TypeScript
以下是我們針對 TypeScript 的 highlights.scm
的一部分範例
; crates/zed/src/languages/typescript/highlights.scm
; Variables
(identifier) @variable
; Properties
(property_identifier) @property
; Function and method calls
(call_expression
function: (identifier) @function)
(call_expression
function: (member_expression
property: (property_identifier) @function.method))
; Function and method definitions
(function
name: (identifier) @function)
(function_declaration
name: (identifier) @function)
(method_definition
name: (property_identifier) @function.method)
; ...