Skip to content

Commit 5f2bed0

Browse files
Update Contributing Docs
1 parent de0405e commit 5f2bed0

File tree

1 file changed

+32
-30
lines changed

1 file changed

+32
-30
lines changed

tools/apiview/parsers/CONTRIBUTING.md

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@
44
This page describes how to contribute to [APIView](../../../src//dotnet/APIView/APIViewWeb/APIViewWeb.csproj) language level parsers.
55
Specifically how to create or update a language parser to produce tree style tokens for APIView.
66

7-
## Object Definitions
8-
## APIView Features
9-
## Serilizations
10-
7+
Previously APIview tokens were created as a flat list assigned to the `CodeFileToken[] Tokens` property of the [CodeFile](../../../src/dotnet/APIView/APIView/Model/CodeFile.cs). Then the page navigation is created and assinged to `NavigationItem[] Navigation`. For tree style tokens these two properties are no longer required, instread a `List<APITreeNode> APIForest` property will be used to capture the generated tree of tokens.
118

12-
13-
## Creating Tree Style Tokens
149
The main idea is to capture the hierachy of the API using a tree data structure, then maintain a flat list of tokens for each node of the tree.
1510

1611
![APITree](APITree.svg)
1712

18-
Each tree node has top tokens which should be used to capture the main tokens on the node, these can span multiple lines. If the language requires it use the bottom tokens to capture tokens that closes out the node, this is usually just the closing bracket and/or empty lines.
13+
Each module of the API (namespace, class, methods) should be its own node. Members of a module (methods, in a class), (classes in a namespace) should be added as child nodes of its parent module.
14+
Each tree node has top tokens which should be used to capture the main tokens on the node, these can span multiple lines. Module name, decorators, and prameters should be modeled as toptokens. If the language requires it use the bottom tokens to capture tokens that closes out the node, this is usually just the closing bracket and/or empty lines.
15+
16+
## Object Definitions
1917

2018
- Here are the models needed
2119
```
@@ -45,58 +43,62 @@ Each tree node has top tokens which should be used to capture the main tokens on
4543
ParameterSeparator
4644
Url
4745
```
48-
### APITreeNode
49-
Each module of the API (namespace, class, method) should be its own node. Members of a module (methods, in a class), (classes in a namespace) should be added as child nodes of its parent module.
50-
51-
Sort each node at each level of the tree by your desired property, this is to ensure that difference in node order does not result in diff.
5246

53-
Ensure each node has an Id. The combination of `Id`, `Kind` and `SubKind` should make the node unique across all nodes in the tree. This is very important. For example a class and a method can potentally have the same Id, but the kind should diffrentiate them from each other.
54-
55-
- `Name` : The name of the tree node which will be used as label for the API Navigation. Generally use the name of the module (class, method)
56-
- `Id` : Id of the node, which should be unique at the node level. i.e. unique among its siblings. Use whatever existing parser is assigning to DefinitionId for the main Token of the node. Each node must have an Id.
57-
- `Kind` : What kind of node is it. Please ensure you set a Kind for each node. Using any of the following `assembly`, `class`, `delegate`, `enum`, `interface`, `method` , `namespace`, `package`, `struct`, `type` will get you the corresponding default icons for the page navigation but feel free to use something language specific.
47+
### APITreeNode
48+
- `Name`: *(Required)* The name of the tree node which will be used as label for the API Navigation. Generally use the name of the module (class, method).
49+
- `Id`: *(Required)* Id of the node, which should be unique at the node level. i.e. unique among its siblings. Use whatever your existing parser is assigning to DefinitionId for the main Token of the node. Each node must have an Id.
50+
- `Kind` *(Required)* : What kind of node is it. Please ensure you set a Kind for each node. Using any of the following `assembly`, `class`, `delegate`, `enum`, `interface`, `method` , `namespace`, `package`, `struct`, `type` will get you the corresponding default icons for the page navigation but feel free to use something language specific then reach out to APIView to support any new name used.
5851
- `Tags` : Use this for opt in or opt out boolean properties. The currently supported tags are
5952
- `Deprecated` Mark a node as deprecated
6053
- `Hidden` Mark a node as Hidden
6154
- `HideFromNavigation` Indicate that anode should be hidden from the page navigation.
6255
- `SkipDiff` Indicate that a node should not be used in computatation of diff.
63-
- `CrossLandDefId` The cross language definitionId for the node.
64-
- `Properties` : Use this for other properties of the node. The currently supported tags
56+
- `CrossLangDefId` The cross language definitionId for the node.
57+
- `Properties` : Use this for other properties of the node. The currently supported keys are
6558
- `SubKind` Similar to kind, use this to make the node more specific. e.g. `Kind = 'Type'`, and `SubKind = 'class'` or somethign specific to you language. We also use this to make the navigation icon it will overide kind.
66-
- `IconName` Use this only if you are looking to add a custom icon different from language wide defaults.
67-
- `TopTokens` : The main data of the node. This is all the tokens that actually define the node. e.g. For a class this would include the access modifier, the class name, any attributes or decorators e.t.c. For a method this would include the return type, method name, parameters e.t.c. See StructureTokesn description below for more info.
59+
- `IconName` Use this only if you are looking to add a custom icon different from language wide defaults. New addtions will need to be supported APIView side.
60+
- `TopTokens` : The main data of the node. This is all the tokens that actually define the node. e.g. For a class this would include the access modifier, the class name, any attributes or decorators e.t.c. For a method this would include the return type, method name, parameters e.t.c. See StructuredToken description below for more info.
6861
- `BottomToken` : Data that closes out the node. Depending on the language this would include the closing curly brace and/or empty lines. You can simulate an empty line by adding an empty token (content token with no value) and a lineBreak token.
6962
- `Children` : The nodes immediate children. For a namespace this would be classes, for a class this would be the class constructors and methods.
7063

64+
65+
Sort each node at each level of the tree by your desired property, this is to ensure that difference in node order does not result in diff.
66+
67+
Ensure each node has an Id and Kind. The combination of `Id`, `Kind` and `SubKind` should make the node unique across all nodes in the tree. This is very important. For example a class and a method can potentally have the same Id, but the kind should diffrentiate them from each other.
68+
69+
Dont worry about indentation that will be handeled by the tree structure, unless you want to have indentation between the tokens then use `TabSpace` token kind.
70+
71+
7172
### StructuredToken
72-
- `Value` : The token value which will be dispalyed. Can be null. Spacing tokens don't need to have value.
73-
- `Id` : This is essentially whatever existing parser was asigning to the token DefinitionId. You dont have to assign a tokenId.
74-
- `Kind` : An enum
73+
- `Value` : The token value which will be dispalyed. Spacing tokens don't need to have value.
74+
- `Id` : This is essentially whatever existing parser was asigning to the token DefinitionId. You dont have to assign a tokenId to everytoken.
75+
- `Kind` *(Required)* : An enum
7576
- `Content` Specifies that the token is content
7677
- `LineBreak` Space token indicating switch to new line.
77-
- `NoneBreakingSpace` Regular single space
78-
- `TabSpace` 4 NoneBreakingSpaces
78+
- `NonBreakingSpace` Regular single space
79+
- `TabSpace` 4 NonBreakingSpaces
7980
- `ParameterSeparator` Use this between method parameters. Depending on user setting this would result in a singlespace or new line
80-
- `Url` A url token should have `LinkText` property and the url/link should be the token value.
81+
- `Url` A url token should have `LinkText` property i.e `token.Properties["LinkText"]` and the url/link should be the token value.
8182
All tokens should be content except for spacing tokens and url. ParameterSeparator should be used between method or function parameters.
8283
- `Tags` : Use this for opt in or opt out boolean properties.The currently supported tags are
8384
- `SkippDiff` Indicate that a token should not be used in computatation of diff.
8485
- `Deprecated` Mark a token as deprecated
8586
- `Properties` : Properties of the token.
8687
- `GroupId` : `doc` to group consecutive comment tokens as documentation.
87-
- `NavigateToId` Id for navigating to where the node where the token is defined. Should match the definitionId of the node.
88+
- `NavigateToId` Id for navigating to where the node where the token is defined. Should match the definitionId of the referenced node.
8889
- `RenderClasses` : Add css classes for how the tokens will be rendred. Classes currently being used are `text` `keyword` `punc` `tname` `mname` `literal` `sliteral` `comment` Feel free to add your own custom class. Whatever custom classes you use please provide us the appriopriate css for the class so we can update APIView.
8990

90-
Dont worry about indentation that will be handeled by the tree structure, unless you want to have indentation between the tokens then use `TabSpace` token kind.
9191

92-
If your packages contains multiple assemblies then you will have multiple trees with multiple roots. Assign the final parsed value to a `List<APITreeNode> APIForest` property of the `CodeFile`.
92+
Assign the final parsed value to a `List<APITreeNode> APIForest` property of the `CodeFile`
93+
94+
## Serilizations
9395

9496
Serialize the generated code file to JSON them compress the file using Gzip compression. Try to make the json as small as possible by ignoring null values and empty collections.
9597

9698
## How to handle commons Scenarios
9799
- TEXT, KEYWORD, COMMENT : Add `text`, `keyword`, `comment` to RenderClasses of the token
98100
- NEW_LINE : Create a token with `Kind = LineBreak`
99-
- WHITE_SPACE : Create token with `Kind = NoneBreakingSpace`
101+
- WHITE_SPACE : Create token with `Kind = NonBreakingSpace`
100102
- PUNCTUATION : Create a token with `Kind = Content` and the `Value = the punctuation`
101103
- DOCUMENTATION : Add `GroupId = doc` in the properties of the token. This identifies a range of consecutive tokens as belonging to a group.
102104
- SKIP_DIFF : Add `SkipDiff` to the Tag to indicate that node or token should not be included in diff computation

0 commit comments

Comments
 (0)