Skip to main content

mz_deploy/lsp/
symbol_kind.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10//! Shared mapping from [`ObjectKind`] to LSP [`SymbolKind`].
11//!
12//! Used by both [`document_symbol`](super::document_symbol) and
13//! [`workspace_symbol`](super::workspace_symbol) to present consistent
14//! icons in the editor's outline and symbol search.
15
16use crate::types::ObjectKind;
17use tower_lsp::lsp_types::SymbolKind;
18
19/// Map an [`ObjectKind`] to an LSP [`SymbolKind`].
20///
21/// LSP has no SQL-specific symbol kinds, so we pick the closest semantic match:
22///
23/// | ObjectKind        | SymbolKind | Rationale                          |
24/// |-------------------|------------|------------------------------------|
25/// | Table             | STRUCT     | Structured row data                |
26/// | View              | FUNCTION   | Computed from a query              |
27/// | MaterializedView  | CLASS      | Persistent computed relation       |
28/// | Source            | INTERFACE  | External data contract             |
29/// | Sink              | MODULE     | Data export target                 |
30/// | Secret            | CONSTANT   | Opaque stored value                |
31/// | Connection        | NAMESPACE  | Named config grouping              |
32pub(super) fn object_kind_to_symbol_kind(kind: ObjectKind) -> SymbolKind {
33    match kind {
34        ObjectKind::Table => SymbolKind::STRUCT,
35        ObjectKind::View => SymbolKind::FUNCTION,
36        ObjectKind::MaterializedView => SymbolKind::CLASS,
37        ObjectKind::Source => SymbolKind::INTERFACE,
38        ObjectKind::Sink => SymbolKind::MODULE,
39        ObjectKind::Secret => SymbolKind::CONSTANT,
40        ObjectKind::Connection => SymbolKind::NAMESPACE,
41    }
42}