Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
name: nightly
name: release

permissions:
contents: write

on:
push:
branches: [non-existent-branch]
tags:
- 'v*'

jobs:
package:
Expand Down Expand Up @@ -86,5 +87,5 @@ jobs:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: build/xpack/clice/${{ matrix.artifact_name }}
asset_name: ${{ matrix.asset_name }}
tag: nightly
tag: ${{ github.ref }}
overwrite: true
6 changes: 3 additions & 3 deletions include/Feature/InlayHint.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ struct InlayHint {
std::vector<index::SymbolID> parts;
};

auto inlay_hint(CompilationUnit& unit,
LocalSourceRange target,
const config::InlayHintsOptions& options) -> std::vector<InlayHint>;
auto inlay_hints(CompilationUnit& unit,
LocalSourceRange target,
const config::InlayHintsOptions& options) -> std::vector<InlayHint>;

} // namespace clice::feature
2 changes: 1 addition & 1 deletion include/Feature/SemanticToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ using SemanticTokens = std::vector<SemanticToken>;
SemanticTokens semantic_tokens(CompilationUnit& unit);

/// Generate semantic tokens for all files.
index::Shared<SemanticTokens> indexSemanticToken(CompilationUnit& unit);
index::Shared<SemanticTokens> index_semantic_token(CompilationUnit& unit);

} // namespace clice::feature

38 changes: 38 additions & 0 deletions include/Server/Convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,44 @@ inline std::uint32_t to_offset(clice::PositionEncodingKind kind,

namespace clice::proto {

inline SymbolKind kind_map(clice::SymbolKind kind) {
switch(kind.kind()) {
case clice::SymbolKind::Comment: return SymbolKind::String;
case clice::SymbolKind::Number: return SymbolKind::Number;
case clice::SymbolKind::Character: return SymbolKind::String;
case clice::SymbolKind::String: return SymbolKind::String;
case clice::SymbolKind::Keyword: return SymbolKind::Variable;
case clice::SymbolKind::Directive: return SymbolKind::Variable;
case clice::SymbolKind::Header: return SymbolKind::String;
case clice::SymbolKind::Module: return SymbolKind::Module;
case clice::SymbolKind::Macro: return SymbolKind::Function;
case clice::SymbolKind::MacroParameter: return SymbolKind::Variable;
case clice::SymbolKind::Namespace: return SymbolKind::Namespace;
case clice::SymbolKind::Class: return SymbolKind::Class;
case clice::SymbolKind::Struct: return SymbolKind::Struct;
case clice::SymbolKind::Union: return SymbolKind::Class;
case clice::SymbolKind::Enum: return SymbolKind::Enum;
case clice::SymbolKind::Type: return SymbolKind::TypeParameter;
case clice::SymbolKind::Field: return SymbolKind::Field;
case clice::SymbolKind::EnumMember: return SymbolKind::EnumMember;
case clice::SymbolKind::Function: return SymbolKind::Function;
case clice::SymbolKind::Method: return SymbolKind::Method;
case clice::SymbolKind::Variable: return SymbolKind::Variable;
case clice::SymbolKind::Parameter: return SymbolKind::Variable;
case clice::SymbolKind::Label: return SymbolKind::Variable;
case clice::SymbolKind::Concept: return SymbolKind::TypeParameter;
case clice::SymbolKind::Attribute: return SymbolKind::Variable;
case clice::SymbolKind::Operator:
case clice::SymbolKind::Paren:
case clice::SymbolKind::Bracket:
case clice::SymbolKind::Brace:
case clice::SymbolKind::Angle: return SymbolKind::Operator;
case clice::SymbolKind::Conflict:
case clice::SymbolKind::Invalid:
default: return SymbolKind::Null;
}
}

json::Value to_json(clice::PositionEncodingKind kind,
llvm::StringRef content,
llvm::ArrayRef<feature::SemanticToken> tokens);
Expand Down
2 changes: 0 additions & 2 deletions include/Server/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ class Server {
async::Task<std::shared_ptr<OpenFile>> add_document(std::string path, std::string content);

private:
async::Task<> publish_diagnostics(std::string path, std::shared_ptr<OpenFile> file);

async::Task<> on_did_open(proto::DidOpenTextDocumentParams params);

async::Task<> on_did_change(proto::DidChangeTextDocumentParams params);
Expand Down
48 changes: 44 additions & 4 deletions src/Feature/DocumentSymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,41 @@ namespace clice::feature {

namespace {

std::string symbol_detail(clang::ASTContext& Ctx, const clang::NamedDecl& ND) {
clang::PrintingPolicy policy(Ctx.getPrintingPolicy());
policy.SuppressScope = true;
policy.SuppressUnwrittenScope = true;
policy.AnonymousTagLocations = false;
policy.PolishForDeclaration = true;

std::string detail;
llvm::raw_string_ostream os(detail);
if(ND.getDescribedTemplateParams()) {
os << "template ";
}

if(const auto* VD = dyn_cast<clang::ValueDecl>(&ND)) {
// FIXME: better printing for dependent type
if(isa<clang::CXXConstructorDecl>(VD)) {
std::string type = VD->getType().getAsString(policy);
// Print constructor type as "(int)" instead of "void (int)".
llvm::StringRef without_void = type;
without_void.consume_front("void ");
os << without_void;
} else if(!isa<clang::CXXDestructorDecl>(VD)) {
VD->getType().print(os, policy);
}
} else if(const auto* TD = dyn_cast<clang::TagDecl>(&ND)) {
os << TD->getKindName();
} else if(isa<clang::TypedefNameDecl>(&ND)) {
os << "type alias";
} else if(isa<clang::ConceptDecl>(&ND)) {
os << "concept";
}

return detail;
}

/// Use DFS to traverse the AST and collect document symbols.
class DocumentSymbolCollector : public FilteredASTVisitor<DocumentSymbolCollector> {

Expand Down Expand Up @@ -50,18 +85,23 @@ class DocumentSymbolCollector : public FilteredASTVisitor<DocumentSymbolCollecto
}

auto ND = llvm::cast<clang::NamedDecl>(decl);
auto [fid, selectionRange] =
auto [fid, selection_range] =
unit.decompose_range(unit.expansion_location(ND->getLocation()));
auto [fid2, range] = unit.decompose_expansion_range(ND->getSourceRange());
if(fid != fid2) {
return true;
}

auto& frame = interested_only ? result : sharedResult[fid];
auto cursor = frame.cursor;

/// Add new symbol.
auto& symbol = frame.cursor->emplace_back();
symbol.kind = SymbolKind::from(decl);
symbol.name = ast::name_of(ND);
symbol.selectionRange = selectionRange;
symbol.range = selectionRange;
symbol.name = ast::display_name_of(ND);
symbol.detail = symbol_detail(unit.context(), *ND);
symbol.selectionRange = selection_range;
symbol.range = range;

/// Adjust the node.
frame.cursor = &symbol.children;
Expand Down
6 changes: 3 additions & 3 deletions src/Feature/InlayHint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,9 +879,9 @@ class Visitor : public FilteredASTVisitor<Visitor> {

} // namespace

auto inlay_hint(CompilationUnit& unit,
LocalSourceRange target,
const config::InlayHintsOptions& options) -> std::vector<InlayHint> {
auto inlay_hints(CompilationUnit& unit,
LocalSourceRange target,
const config::InlayHintsOptions& options) -> std::vector<InlayHint> {
std::vector<InlayHint> hints;

Builder builder(hints, unit, target, options);
Expand Down
2 changes: 1 addition & 1 deletion src/Feature/SemanticToken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ SemanticTokens semantic_tokens(CompilationUnit& unit) {
return std::move(collector.result);
}

index::Shared<SemanticTokens> indexSemanticToken(CompilationUnit& unit) {
index::Shared<SemanticTokens> index_semantic_token(CompilationUnit& unit) {
SemanticTokensCollector collector(unit, false);
for(auto fid: unit.files()) {
collector.highlight(fid);
Expand Down
2 changes: 1 addition & 1 deletion src/Index/FeatureIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ feature::DocumentSymbols FeatureIndex::documentSymbols() const {
Shared<std::vector<char>> FeatureIndex::build(CompilationUnit& unit) {
Shared<memory::FeatureIndex> indices;

for(auto&& [fid, result]: feature::indexSemanticToken(unit)) {
for(auto&& [fid, result]: feature::index_semantic_token(unit)) {
indices[fid].tokens = std::move(result);
}

Expand Down
37 changes: 17 additions & 20 deletions src/Server/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ void Server::load_cache_info() {
auto mtime = object->getNumber("mtime");
auto deps = object->getArray("deps");
auto arguments = object->getArray("arguments");
auto includes = object->get("includes");

if(!file || !path || !preamble || !mtime || !deps || !arguments) {
if(!file || !path || !preamble || !mtime || !deps || !arguments || !includes) {
Comment thread
16bit-ykiko marked this conversation as resolved.
continue;
}

Expand All @@ -67,7 +68,10 @@ void Server::load_cache_info() {
}

/// Update the PCH info.
opening_files.get_or_add(*file)->pch = std::move(info);
auto opening_file = opening_files.get_or_add(*file);
opening_file->pch = std::move(info);
opening_file->pch_includes =
json::deserialize<decltype(opening_file->pch_includes)>(*includes);
}
}

Expand All @@ -92,6 +96,7 @@ void Server::save_cache_info() {
object["mtime"] = pch.mtime;
object["deps"] = json::serialize(pch.deps);
object["arguments"] = json::serialize(pch.arguments);
object["includes"] = json::serialize(open_file->pch_includes);

json["pchs"].getAsArray()->emplace_back(std::move(object));
}
Expand Down Expand Up @@ -313,6 +318,15 @@ async::Task<> Server::build_ast(std::string path, std::string content) {
co_return;
}

/// Send diagnostics
auto diagnostics = co_await async::submit(
[&, kind = this->kind] { return feature::diagnostics(kind, mapping, *ast); });
co_await notify("textDocument/publishDiagnostics",
json::Object{
{"uri", mapping.to_uri(path) },
{"diagnostics", std::move(diagnostics)},
});

/// FIXME: Index the source file.
/// co_await indexer.index(*ast);

Expand All @@ -327,6 +341,7 @@ async::Task<> Server::build_ast(std::string path, std::string content) {

async::Task<std::shared_ptr<OpenFile>> Server::add_document(std::string path, std::string content) {
auto& openFile = opening_files.get_or_add(path);
openFile->version += 1;
openFile->content = content;

auto& task = openFile->ast_build_task;
Expand All @@ -350,33 +365,15 @@ async::Task<std::shared_ptr<OpenFile>> Server::add_document(std::string path, st
co_return openFile;
}

async::Task<> Server::publish_diagnostics(std::string path, std::shared_ptr<OpenFile> file) {
auto guard = co_await file->ast_built_lock.try_lock();
if(file->ast) {
auto diagnostics = feature::diagnostics(kind, mapping, *file->ast);
co_await notify("textDocument/publishDiagnostics",
json::Object{
{"uri", mapping.to_uri(path) },
{"diagnostics", std::move(diagnostics)},
});
}
}

async::Task<> Server::on_did_open(proto::DidOpenTextDocumentParams params) {
auto path = mapping.to_path(params.textDocument.uri);
auto file = co_await add_document(path, std::move(params.textDocument.text));
if(file->diagnostics) {
co_await publish_diagnostics(path, std::move(file));
}
co_return;
}

async::Task<> Server::on_did_change(proto::DidChangeTextDocumentParams params) {
auto path = mapping.to_path(params.textDocument.uri);
auto file = co_await add_document(path, std::move(params.contentChanges[0].text));
if(file->diagnostics) {
co_await publish_diagnostics(path, std::move(file));
}
co_return;
}

Expand Down
Loading