Zedに新規言語を追加する

LSP

Zedでは、言語サーバープロトコルを使用して言語サポートが提供されています。理論的には、LSPサーバーのある言語であれば、どんな言語でもサポートできます。

構文のハイライト

構文ハイライトのルールを定義する

ハイライトする特定のプロパティと一致させるには、tree-sitterクエリを使用します。

シンプルな例

(property_identifier) @property
const font: FontFamily = {
  weight: "normal",
  underline: false,
  italic: false,
};

プロパティ識別子と一致させて、識別子@propertyを使用してハイライトします。上記の例では、weightunderlineitalicがハイライトされます。

複雑な例

(_
  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)

; ...