Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Changes for the language server #254

Merged
merged 20 commits into from
Jun 19, 2024
Merged

Changes for the language server #254

merged 20 commits into from
Jun 19, 2024

Conversation

alxkzmn
Copy link
Collaborator

@alxkzmn alxkzmn commented May 30, 2024

The following changes were necessary to integrate with the language server:

  • Usages tracking for SymTableEntry (and some WIP additional functionality in the Analyzer to record the usages during the analysis).
  • "Reverse" lookup by offset in SymTable
  • File reference in DebugSymRef changes from Rc to Arc because the language server is asynchronous.

@alxkzmn alxkzmn requested a review from leolara May 30, 2024 06:26
@alxkzmn
Copy link
Collaborator Author

alxkzmn commented May 30, 2024

I see that some tests are failing due to the new usages field in the SymTableEntry, but I'd rather fix them only if the changes make it through the review 😃

@alxkzmn alxkzmn requested a review from leolara June 7, 2024 10:37
@leolara
Copy link
Collaborator

leolara commented Jun 8, 2024

so, now the changes to the analyser are missing?

@alxkzmn
Copy link
Collaborator Author

alxkzmn commented Jun 8, 2024

@leolara maybe I misunderstood but I thought that the conclusion was to extract the usages in a separate pass and put them in a separate data structure. In this case it could all be done in the language server.

@leolara
Copy link
Collaborator

leolara commented Jun 8, 2024

@alxkzmn That is not the conclusion: #254 (comment)

The conclusion is to remove the lines that check if the state symbol is there and create it if it is not. The state symbol will be there.

@alxkzmn
Copy link
Collaborator Author

alxkzmn commented Jun 10, 2024

@leolara to make sure I'm on the right track:

  • it's OK to process the usages while analyzing, all in single pass;
  • the usages should be recorded to a separate data structure.
    Is this correct?

@leolara
Copy link
Collaborator

leolara commented Jun 10, 2024

Yes, single pass, you don't need a separate data structure. What you had before is ok, just needs to assume that the states are already in the symbol table, because they should be. As I explained, we are already doing kind of two passes, one to collect the state symbols and then to analyse each state after. So when you are analysing a transition you already should have the state in the symbol table

@alxkzmn
Copy link
Collaborator Author

alxkzmn commented Jun 10, 2024

@leolara the PR is ready for review.

@@ -62,7 +62,9 @@ impl Analyser {
block,
} => {
let sym = SymTableEntry {
id: id.name(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

@alxkzmn perhaps we could have a constructor new that always sets usages to vec![]

.into_iter()
.for_each(|expr| self.analyse_expression(expr)),
Statement::SignalAssignment(_, ids, exprs) => {
self.extract_id_usages(&ids);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@alxkzmn wouldn't it be better to extract the usages after the semantic analysis? I mean swaping the calls to extract_id_usages and analyse_expression ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, at least it seems more intuitively to make more sense to analyse first and then extract the usages

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The IDs weren't initially used (_), so shouldn't be any difference (only affects the order in which they are recorded). But I'll rename and move the method after the analysis, just in case.

src/parser/ast/mod.rs Outdated Show resolved Hide resolved
@alxkzmn alxkzmn requested review from leolara and rutefig June 17, 2024 07:32

/// Returns the proximity score of the given offset to the debug symbol.
/// The proximity score is the sum of the distance from the start and end of the symbol.
/// If the offset is not within the symbol, -1 is returned.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The comment is no longer valid

@leolara
Copy link
Collaborator

leolara commented Jun 18, 2024

I put all my ideas here together to avoid more cycles:

@alxkzmn alxkzmn requested a review from leolara June 18, 2024 09:47
/// ### Returns
/// The `SymTableEntry` that is closest to the offset.
pub fn find_symbol_by_offset(&self, filename: String, offset: usize) -> Option<SymTableEntry> {
let mut closest_symbol: Option<SymTableEntry> = None;
Copy link
Collaborator

Choose a reason for hiding this comment

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

@alxkzmn I think it would be much more efficient and clear to store the closest_symbol_proximity in a variable instead of calling proximity score every time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I initially wanted to do that but then refactored into calling the method for readability because it seemed like overoptimizing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it also make it more readbale, also perhaps you could have an and in the two conditions, although I think that feature with if let is experimental.

But I also thought for a moment that proximity_score had a couple of loops inside so I thought it was more important.

@leolara
Copy link
Collaborator

leolara commented Jun 19, 2024

It was aprove already, you can merge

@alxkzmn alxkzmn merged commit b023b4e into chiquito-2024 Jun 19, 2024
4 checks passed
@alxkzmn alxkzmn deleted the language-server branch June 19, 2024 04:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants