-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Find comments for symbol function #67
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
Tobiky
merged 6 commits into
mal-lang:master
from
tagyieh:feat/find_comments_for_symbol_function
Aug 27, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b37685b
feat: Find comments associated with symbol function.
tagyieh ddc57c6
tests: Find comments associated with symbol function.
tagyieh 19172e5
chore: Filter comments based on rows.
tagyieh 09c1561
tests: Negative test cases.
tagyieh 41789a7
fix: Correct linter errors.
tagyieh 6016742
chore: Use filter function.
tagyieh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #id: "org.mal-lang.testAnalyzer" | ||
| #version:"0.0.0" | ||
|
|
||
| // should not appear | ||
| /* | ||
| * SHOULD NOT APPEAR | ||
| */ | ||
|
|
||
| // category comment | ||
| category Example { | ||
|
|
||
| // should not appear | ||
|
|
||
| // asset comment 1 | ||
| // asset comment 2 | ||
| asset Asset1 | ||
| { | ||
| | compromise | ||
| -> b.compromise | ||
| } | ||
|
|
||
| /* | ||
| * SHOULD NOT APPEAR | ||
| */ | ||
|
|
||
| /* | ||
| * MULTI-LINE COMMENT | ||
| */ | ||
| // followed by single comment | ||
| asset Asset2 | ||
| { | ||
| | compromise | ||
| // attack_step comment | ||
| & attack | ||
| } | ||
|
|
||
| /* | ||
| * SHOULD NOT APPEAR | ||
| */ | ||
| // should not appear | ||
|
|
||
| // asset3 comment | ||
| asset | ||
| Asset3 { } | ||
|
|
||
| asset | ||
| // asset4 comment | ||
| Asset4 { } | ||
| } | ||
| associations | ||
| { | ||
| // should not appear | ||
| // should not appear | ||
|
|
||
| // association comment | ||
| Asset1 [a] * <-- L --> * [c] Asset2 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| import tree_sitter_mal as ts_mal | ||
| from tree_sitter import Language, Parser | ||
|
|
||
| from malls.lsp.classes import Document | ||
| from malls.lsp.utils import recursive_parsing | ||
| from malls.ts.utils import INCLUDED_FILES_QUERY, find_comments_function, run_query | ||
|
|
||
| MAL_LANGUAGE = Language(ts_mal.language()) | ||
| PARSER = Parser(MAL_LANGUAGE) | ||
| FILE_PATH = str(Path(__file__).parent.parent.resolve()) + "/fixtures/mal/" | ||
|
|
||
| parameters = [ | ||
| ((9, 13), [b"// category comment"]), | ||
| ((15, 12), [b"// asset comment 1", b"// asset comment 2"]), | ||
| ((29, 12), [b"/* \n * MULTI-LINE COMMENT\n */", b"// followed by single comment"]), | ||
| ((33, 12), [b"// attack_step comment"]), | ||
| ((43, 8), []), | ||
| ((47, 6), [b"// asset4 comment"]), | ||
| ((55, 21), [b"// association comment"]), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "point,comments", | ||
| parameters, | ||
| ) | ||
| def test_find_comments_for_symbol_function(mal_find_comments_for_symbol_function, point, comments): | ||
| # build the storage (mimicks the file parsing in the server) | ||
| storage = {} | ||
|
|
||
| doc_uri = FILE_PATH + "find_comments_for_symbol_function.mal" | ||
| source_encoded = mal_find_comments_for_symbol_function.read() | ||
| tree = PARSER.parse(source_encoded) | ||
|
|
||
| storage[doc_uri] = Document(tree, source_encoded, doc_uri) | ||
|
|
||
| # obtain the included files | ||
| root_node = tree.root_node | ||
|
|
||
| captures = run_query(root_node, INCLUDED_FILES_QUERY) | ||
| if "file_name" in captures: | ||
| recursive_parsing(FILE_PATH, captures["file_name"], storage, doc_uri, []) | ||
|
|
||
| ################################### | ||
|
|
||
| # get the node | ||
| cursor = tree.walk() | ||
| while cursor.goto_first_child_for_point(point) is not None: | ||
| continue | ||
|
|
||
| # confirm it's an identifier | ||
| assert cursor.node.type == "identifier" | ||
|
|
||
| # we use sets to ensure order does not matter | ||
| returned_comments = find_comments_function(cursor.node, cursor.node.text, doc_uri, storage) | ||
|
|
||
| assert set(returned_comments) == set(comments) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.