CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
78 lines
2.5 KiB
C++
78 lines
2.5 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLDB_SOURCE_PLUGINS_HIGHLIGHTER_TREESITTER_TREESITTERHIGHLIGHTER_H
|
|
#define LLDB_SOURCE_PLUGINS_HIGHLIGHTER_TREESITTER_TREESITTERHIGHLIGHTER_H
|
|
|
|
#include "lldb/Core/Highlighter.h"
|
|
#include "lldb/Utility/Stream.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include <optional>
|
|
#include <tree_sitter/api.h>
|
|
|
|
namespace lldb_private {
|
|
|
|
struct TSState;
|
|
|
|
class TreeSitterHighlighter : public Highlighter {
|
|
public:
|
|
TreeSitterHighlighter() = default;
|
|
~TreeSitterHighlighter() override = default;
|
|
|
|
/// Highlights a single line of code using tree-sitter parsing.
|
|
void Highlight(const HighlightStyle &options, llvm::StringRef line,
|
|
std::optional<size_t> cursor_pos,
|
|
llvm::StringRef previous_lines, Stream &s) const override;
|
|
|
|
protected:
|
|
/// Returns the tree-sitter language for this highlighter.
|
|
virtual const TSLanguage *GetLanguage() const = 0;
|
|
|
|
/// Returns the tree-sitter highlight query for this language.
|
|
virtual llvm::StringRef GetHighlightQuery() const = 0;
|
|
|
|
private:
|
|
/// Maps a tree-sitter capture name to a HighlightStyle color.
|
|
HighlightStyle::ColorStyle
|
|
GetStyleForCapture(llvm::StringRef capture_name,
|
|
const HighlightStyle &options) const;
|
|
|
|
/// Applies syntax highlighting to a range of text.
|
|
void HighlightRange(const HighlightStyle &options, llvm::StringRef text,
|
|
uint32_t start_byte, uint32_t end_byte,
|
|
const HighlightStyle::ColorStyle &style,
|
|
std::optional<size_t> cursor_pos,
|
|
bool &highlighted_cursor, Stream &s) const;
|
|
|
|
struct HLRange {
|
|
uint32_t start_byte;
|
|
uint32_t end_byte;
|
|
HighlightStyle::ColorStyle style;
|
|
};
|
|
|
|
struct TSState {
|
|
TSState() = default;
|
|
TSState &operator=(const TSState &) = delete;
|
|
TSState(const TSState &) = delete;
|
|
~TSState();
|
|
|
|
explicit operator bool() const;
|
|
TSParser *parser = nullptr;
|
|
TSQuery *query = nullptr;
|
|
};
|
|
|
|
/// Lazily creates a tree-sitter state (TSState).
|
|
TSState &GetTSState() const;
|
|
mutable std::optional<TSState> m_ts_state;
|
|
};
|
|
|
|
} // namespace lldb_private
|
|
|
|
#endif // LLDB_SOURCE_PLUGINS_LANGUAGE_TREESITTERCOMMON_TREESITTERHIGHLIGHTER_H
|