Skip to content

Designate doc comments #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 10, 2022
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
30 changes: 30 additions & 0 deletions corpus/source_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,36 @@ Line comments
(source_file
(line_comment))

============================================
Doc comments
============================================

/// Doc
/// Comment
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//! as well.

But I think //!! will become normal comment. The last I worked on is this

https://github.com/mawww/kakoune/blob/871782faaf954cda654cdbdcb3590b45534607d1/rc/filetype/rust.kak#L46-L49

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From https://doc.rust-lang.org/reference/comments.html#examples

//! - Inner line doc
//!! - Still an inner line doc (but with a bang at the beginning)

So I implemented it as "any ! makes it a doc comment, no matter how many"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's only up till four, IIRC it's the same highlight in vim.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In SpaceVim (without LSP) the highlight is different (grey for comments, orange for doc comments) and that was really useful IMHO.

// / Now a line comment (note the space separating the third slash)

/// Doc
/// Comment
//// Four slashes makes the line a normal comment
/// Doc comment got interrupted by the line above

//! Inner doc comment line 1
//! Inner doc comment line 2
/// This is different doc comment since the line starts differently
//! Back to inner doc comment

----

(source_file
(doc_comment)
(line_comment)
(doc_comment)
(line_comment)
(doc_comment)
(doc_comment)
(doc_comment)
(doc_comment))

=====================================
Greek letters in identifiers
=====================================
Expand Down
13 changes: 3 additions & 10 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ const primitive_types = numeric_types.concat(['bool', 'str', 'char'])
module.exports = grammar({
name: 'rust',

extras: $ => [/\s/, $.line_comment, $.block_comment],
extras: $ => [/\s/, $.line_comment, $.block_comment, $.doc_comment],

externals: $ => [
$._string_content,
$.raw_string_literal,
$.float_literal,
$.block_comment,
$.line_comment,
$.doc_comment
],

supertypes: $ => [
Expand Down Expand Up @@ -1426,15 +1428,6 @@ module.exports = grammar({

boolean_literal: $ => choice('true', 'false'),

comment: $ => choice(
$.line_comment,
$.block_comment
),

line_comment: $ => token(seq(
'//', /.*/
)),

_path: $ => choice(
$.self,
alias(choice(...primitive_types), $.identifier),
Expand Down
41 changes: 12 additions & 29 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -8173,35 +8173,6 @@
}
]
},
"comment": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "line_comment"
},
{
"type": "SYMBOL",
"name": "block_comment"
}
]
},
"line_comment": {
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "//"
},
{
"type": "PATTERN",
"value": ".*"
}
]
}
},
"_path": {
"type": "CHOICE",
"members": [
Expand Down Expand Up @@ -8382,6 +8353,10 @@
{
"type": "SYMBOL",
"name": "block_comment"
},
{
"type": "SYMBOL",
"name": "doc_comment"
}
],
"conflicts": [
Expand Down Expand Up @@ -8427,6 +8402,14 @@
{
"type": "SYMBOL",
"name": "block_comment"
},
{
"type": "SYMBOL",
"name": "line_comment"
},
{
"type": "SYMBOL",
"name": "doc_comment"
}
],
"inline": [
Expand Down
4 changes: 4 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -4939,6 +4939,10 @@
"type": "default",
"named": false
},
{
"type": "doc_comment",
"named": true
},
{
"type": "dyn",
"named": false
Expand Down
Loading