Skip to content

Commit fbdf9ea

Browse files
authored
Feature/issue 109 docu (#122)
* feat: write some basic Rustdoc * test rustdoc github action * github action permission * feat: move action into ide * feat: add basic Comments and documentation to files * some more fine tuning for the documentation * fix: add automatic redirect to right github page * fix github action * feat: Docs cleanup * feat: restrict github action condition * feat: change docs link
1 parent 99ff1ac commit fbdf9ea

31 files changed

Lines changed: 483 additions & 261 deletions

.github/workflows/rustdoc.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: rustdoc
2+
on:
3+
pull_request:
4+
branches: [ "master" ]
5+
6+
7+
env:
8+
CARGO_INCREMENTAL: 0
9+
CARGO_NET_RETRY: 10
10+
RUSTFLAGS: "-D warnings -W unreachable-pub"
11+
RUSTUP_MAX_RETRIES: 10
12+
13+
jobs:
14+
rustdoc:
15+
runs-on: ubuntu-latest
16+
17+
permissions:
18+
contents: write
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v3
23+
24+
- name: Install Rust toolchain
25+
run: rustup update --no-self-update stable
26+
27+
- name: Build Documentation
28+
run: cargo doc --all --no-deps
29+
30+
- name: relink Github pages
31+
# Add redirect to uvls doc site as main Page
32+
run: echo '<meta http-equiv="refresh" content="0; url=./uvls" />' > ./target/doc/index.html
33+
34+
- name: Deploy Docs
35+
uses: peaceiris/actions-gh-pages@364c31d33bb99327c77b3a5438a83a357a6729ad # v3.4.0
36+
with:
37+
github_token: ${{ secrets.GITHUB_TOKEN }}
38+
publish_branch: gh-pages
39+
publish_dir: ./target/doc
40+
force_orphan: true

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
[UVL](https://github.com/Universal-Variability-Language) language server based on [tree-sitter](https://github.com/tree-sitter/tree-sitter).
33

44
## Getting started
5+
6+
### Docs
7+
Basic Documentation for the Codebase: [Docs](https://universal-variability-language.github.io/uvl-lsp/uvls/)
58
### Build
69
- Requirements
710
- Rust 1.65+
@@ -60,6 +63,3 @@ we can capture many incorrect expressions and provide decent error messages in m
6063
Tree-sitter queries allow for easy symbol extraction and are used to transform the tree-sitter tree into a more compact graph.
6164
This graph is then used for further analysis.
6265
Queries are also used for syntax highlighting as tree-sitter was originally intended for that.
63-
64-
65-

uvls/src/core/ast.rs

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
//! Easy to work with AST parsing and util.
2+
//!
3+
//! The AST is stored as an ECS like structure
4+
//! This allows fast queries over all features groups etc.
5+
//! Features, Attributes, Imports and Directories are stored in a typed radix tree.
6+
//! The radix tree is represented via a map (sym0,name,ty) -> sym1
7+
//! where ty is the type of sym1. Using this representation lowers total
8+
//! memory consumption by a nice 20%
9+
110
use crate::core::*;
211
use check::ErrorInfo;
312
use hashbrown::HashMap;
@@ -18,13 +27,7 @@ mod transform;
1827
mod visitor;
1928
pub use def::*;
2029
pub use visitor::*;
21-
//Easy to work with AST parsing and util.
22-
//The AST is stored as an ECS like structure
23-
//This allows fast queries over all features groups etc.
24-
//Features, Attributes, Imports and Directories are stored in a typed radix tree.
25-
//The radix tree is represented via a map (sym0,name,ty) -> sym1
26-
//where ty is the type of sym1. Using this representation lowers total
27-
//memory consumption by a nice 20%
30+
2831
pub fn uri_to_path(uri: &Url) -> Option<Vec<Ustr>> {
2932
let mut p = uri.to_file_path().ok()?;
3033
p.set_extension("");
@@ -47,7 +50,7 @@ where
4750
}
4851
}
4952

50-
//1->N parent child relation
53+
/// 1->N parent child relation
5154
#[derive(Default, Debug, Clone)]
5255
struct TreeMap {
5356
children: HashMap<Symbol, Vec<Symbol>>,
@@ -59,7 +62,7 @@ impl TreeMap {
5962
self.parent.insert(child, parent);
6063
}
6164
}
62-
//Ast container each symbol kind lives in its own vector
65+
/// Ast container each symbol kind lives in its own vector
6366
#[derive(Clone, Debug, Default)]
6467
struct Ast {
6568
keywords: Vec<Keyword>,
@@ -90,7 +93,7 @@ impl Ast {
9093
_ => unimplemented!(),
9194
}
9295
}
93-
//call f for each child under sym and prefix
96+
/// call f for each child under sym and prefix
9497
fn lookup<F: FnMut(Symbol)>(&self, sym: Symbol, prefix: Ustr, mut f: F) {
9598
match sym {
9699
Symbol::Root => {
@@ -143,7 +146,7 @@ impl Ast {
143146
fn lsp_range(&self, sym: Symbol, source: &Rope) -> Option<tower_lsp::lsp_types::Range> {
144147
self.span(sym).and_then(|s| lsp_range(s, source))
145148
}
146-
//source range for a symbol if there is any
149+
/// source range for a symbol if there is any
147150
fn span(&self, sym: Symbol) -> Option<Span> {
148151
match sym {
149152
Symbol::Feature(i) => Some(self.features[i].name.span.clone()),
@@ -171,7 +174,7 @@ impl Ast {
171174
.into_iter()
172175
.flat_map(|v| v.iter().cloned())
173176
}
174-
//utility iterators over different elements of interest
177+
/// utility iterators over different elements of interest
175178
fn all_imports(&self) -> impl Iterator<Item = Symbol> + DoubleEndedIterator {
176179
(0..self.import.len()).map(Symbol::Import)
177180
}
@@ -217,7 +220,7 @@ impl Ast {
217220
fn all_lang_lvls(&self) -> impl Iterator<Item = Symbol> {
218221
(0..self.includes.len()).map(Symbol::LangLvl)
219222
}
220-
//Search a symbol by byte offset in O(N)
223+
/// Search a symbol by byte offset in O(N)
221224
fn find(&self, offset: usize) -> Option<Symbol> {
222225
self.all_imports()
223226
.chain(self.all_features())
@@ -250,7 +253,7 @@ impl Ast {
250253
return relatives;
251254
}
252255
}
253-
//Combines the AST with metadata, this is also a public interface to the AST.
256+
/// Combines the AST with metadata, this is also a public interface to the AST.
254257
#[derive(Clone, Debug)]
255258
pub struct AstDocument {
256259
ast: Ast,
@@ -270,7 +273,7 @@ impl AstDocument {
270273
self.ast.structure.parent.get(&sym).cloned()
271274
}
272275
}
273-
//parent feature of an attribute
276+
/// parent feature of an attribute
274277
pub fn scope(&self, mut sym: Symbol) -> Symbol {
275278
while let Some(p) = self.parent(sym, true) {
276279
match sym {
@@ -285,7 +288,7 @@ impl AstDocument {
285288
pub fn name(&self, sym: Symbol) -> Option<Ustr> {
286289
self.ast.name(sym)
287290
}
288-
//iterators over diffrent symbole types in the tree
291+
/// iterators over diffrent symbole types in the tree
289292
pub fn all_lang_lvls(&self) -> impl Iterator<Item = Symbol> {
290293
self.ast.all_lang_lvls()
291294
}
@@ -396,8 +399,8 @@ impl AstDocument {
396399
_ => 0,
397400
}
398401
}
399-
//Find all symboles under root with prefix path.
400-
//Search branches can be aborted with a filter
402+
/// Find all symboles under root with prefix path.
403+
/// Search branches can be aborted with a filter
401404
pub fn lookup<'a, F: Fn(Symbol) -> bool + 'a>(
402405
&'a self,
403406
root: Symbol,
@@ -417,7 +420,7 @@ impl AstDocument {
417420
})
418421
})
419422
}
420-
//Find imports for any prefix of path
423+
/// Find imports for any prefix of path
421424
pub fn lookup_import<'a>(
422425
&'a self,
423426
path: &'a [Ustr],
@@ -441,7 +444,7 @@ impl AstDocument {
441444
}
442445
})
443446
}
444-
//Also track the binding for path, each segment of path has some symbole bound to it
447+
/// Also track the binding for path, each segment of path has some symbole bound to it
445448
pub fn lookup_with_binding<'a, F: Fn(Symbol) -> bool + 'a>(
446449
&'a self,
447450
root: Symbol,
@@ -461,7 +464,7 @@ impl AstDocument {
461464
})
462465
})
463466
}
464-
// returns all Symbols with same name, used for cardinality resolving
467+
/// returns all Symbols with same name, used for cardinality resolving
465468
pub fn get_all_entities(&self, path: &[Ustr]) -> Vec<Symbol> {
466469
let ustr_path = Ustr::from(path.iter().map(|s| s.to_string()).join(".").as_str());
467470
let mut res = vec![];
@@ -510,7 +513,7 @@ impl AstDocument {
510513
res
511514
}
512515

513-
//prefix of sym from root
516+
/// prefix of sym from root
514517
pub fn prefix(&self, mut sym: Symbol) -> Vec<Ustr> {
515518
if matches!(sym, Symbol::Import(..)) {
516519
return self.ast.import_prefix(sym).into();
@@ -551,7 +554,7 @@ impl AstDocument {
551554
pub fn find(&self, offset: usize) -> Option<Symbol> {
552555
self.ast.find(offset)
553556
}
554-
//All children under root, when merge_root_features sub features are ignored
557+
/// All children under root, when merge_root_features sub features are ignored
555558
pub fn visit_named_children<F: FnMut(Symbol, &[Ustr]) -> bool>(
556559
&self,
557560
root: Symbol,
@@ -560,7 +563,7 @@ impl AstDocument {
560563
) {
561564
self.visit_named_children_depth(root, merge_root_features, |sym, prefix, _| f(sym, prefix))
562565
}
563-
//Iterate all named symbole under root and track their prefix from root
566+
/// Iterate all named symbole under root and track their prefix from root
564567
pub fn visit_named_children_depth<F: FnMut(Symbol, &[Ustr], usize) -> bool>(
565568
&self,
566569
root: Symbol,
@@ -612,7 +615,7 @@ impl AstDocument {
612615
pub fn find_all_of(&self, name: Ustr) -> Vec<Symbol> {
613616
self.ast.find_all_of(Symbol::Root, name)
614617
}
615-
//Iterate all named symbole under root
618+
/// Iterate all named symbole under root
616619
pub fn visit_children_depth<F: FnMut(Symbol, u32) -> bool>(
617620
&self,
618621
root: Symbol,
@@ -645,7 +648,7 @@ impl AstDocument {
645648
}
646649
}
647650
}
648-
//Iterate all attributes under root, and track theire associated feature
651+
/// Iterate all attributes under root, and track theire associated feature
649652
pub fn visit_attributes<'a, F: FnMut(Symbol, Symbol, &[Ustr])>(&self, root: Symbol, mut f: F) {
650653
assert!(matches!(root, Symbol::Feature(..) | Symbol::Root));
651654
let mut owner = root;

uvls/src/core/ast/collapse.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Transform a tree-sitter tree into the Ast ECS via recursive decent
2+
//! While parsing we keep a mutable state to store entities and errors
3+
14
use crate::core::*;
25
use ast::visitor::Visitor;
36
use ast::visitor::*;
@@ -19,8 +22,6 @@ impl Collapse {
1922
}
2023
}
2124

22-
//Transform a tree-sitter tree into the Ast ECS via recursive decent
23-
//While parsing we keep a mutable state to store entities and errors
2425
#[derive(Clone)]
2526
struct VisitorCollapse<'a> {
2627
cursor: TreeCursor<'a>,
@@ -55,7 +56,7 @@ impl<'a> VisitorCollapse<'a> {
5556
});
5657
}
5758

58-
//get the current block header
59+
/// get the current block header
5960
fn header(&self) -> Option<Node<'a>> {
6061
self.node().child_by_field_name("header")
6162
}
@@ -65,7 +66,7 @@ impl<'a> VisitorCollapse<'a> {
6566
self.levels[line] = self.current_level;
6667
}
6768

68-
// Add ranges based on self.levels vec
69+
/// Add ranges based on self.levels vec
6970
fn calculate_ranges(&mut self) -> () {
7071
// Skip comments
7172
let first_nonzero_line = self
@@ -181,8 +182,8 @@ fn visit_top_lvl(collapse: &mut VisitorCollapse) {
181182
}
182183
}
183184
}
184-
//visits all valid children of a tree-sitter (red tree) recursively to translate them into the
185-
//Collapse struct
185+
/// visits all valid children of a tree-sitter (red tree) recursively to translate them into the
186+
/// Collapse struct
186187
pub fn visit_root(source: Rope, tree: Tree, uri: Url) -> Collapse {
187188
let mut c = VisitorCollapse {
188189
cursor: tree.walk(),

uvls/src/core/ast/def.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//Basic Ast components
1+
//! Basic Ast components
22
use enumflags2::bitflags;
33
use itertools::Itertools;
44
use ustr::Ustr;
@@ -48,7 +48,7 @@ impl Path {
4848
}
4949
}
5050

51-
//Type definitions for symbols
51+
/// Type definitions for symbols
5252
#[bitflags]
5353
#[repr(u8)]
5454
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -272,7 +272,7 @@ pub struct ExprDecl {
272272
pub content: Expr,
273273
pub span: Span,
274274
}
275-
//A symbol represents an entity in some uvl document
275+
/// A symbol represents an entity in some uvl document
276276
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, enum_kinds::EnumKind)]
277277
#[enum_kind(SymbolKind, derive(Hash))]
278278
pub enum Symbol {

uvls/src/core/ast/graph.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use std::borrow::{Borrow, Cow};
1+
//! Transform a tree-sitter tree into the Ast ECS via recursive decent
2+
//! While parsing we keep a mutable state to store entities and errors
23
34
use crate::core::*;
45
use ast::visitor::Visitor;
@@ -7,6 +8,7 @@ use check::ErrorInfo;
78
use html_escape::encode_text;
89
use parse::*;
910
use ropey::Rope;
11+
use std::borrow::{Borrow, Cow};
1012
use tower_lsp::lsp_types::Url;
1113
use tree_sitter::{Node, Tree, TreeCursor};
1214

@@ -61,8 +63,6 @@ impl Default for GraphNode {
6163
}
6264
}
6365

64-
//Transform a tree-sitter tree into the Ast ECS via recursive decent
65-
//While parsing we keep a mutable state to store entities and errors
6666
#[derive(Clone)]
6767
struct VisitorGraph<'a> {
6868
cursor: TreeCursor<'a>,
@@ -84,7 +84,7 @@ impl<'a> Visitor<'a> for VisitorGraph<'a> {
8484
}
8585

8686
impl<'a> VisitorGraph<'a> {
87-
// Generate Graph Code:
87+
/// Generate Graph Code:
8888
8989
fn begin(&mut self) {
9090
self.dot.push_str(&"digraph FeatureModel {\nrankdir=\"TB\"\nnewrank=true\nnode [style=filled fontname=\"Arial Unicode MS, Arial\"];\n\n".to_string());
@@ -205,7 +205,7 @@ impl<'b> SymbolSlice for VisitorGraph<'b> {
205205
}
206206
}
207207

208-
//parse a namespace
208+
/// parse a namespace
209209
fn visit_namespace(graph: &mut VisitorGraph) {
210210
loop {
211211
if graph.kind() == "namespace" {
@@ -317,7 +317,7 @@ fn opt_int(node: Node, state: &mut VisitorGraph) -> Option<usize> {
317317
None
318318
}
319319
}
320-
// returns cardinality for Node
320+
/// returns cardinality for Node
321321
fn opt_cardinality(node: Node, state: &mut VisitorGraph) -> Option<Cardinality> {
322322
let begin = node.child_by_field_name("begin");
323323
let end = node.child_by_field_name("end");

0 commit comments

Comments
 (0)