Skip to content
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

Analysis #457

Merged
merged 23 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ec2b556
First pass at `%Lexical.Ast.Analysis{}`
zachallaun Oct 31, 2023
cc896e7
Temporarily use forked Sourceror with range fix
zachallaun Oct 31, 2023
2e6b5a0
Add safe analysis api and simplify expand_aliases
zachallaun Nov 1, 2023
60bb1a2
PR feedback and fix alias override bug
zachallaun Nov 1, 2023
2ce2a84
Delete `Ast.Aliases` and move tests to `Analysis`
zachallaun Nov 1, 2023
1b2590d
Support derived document data in store with derivations
zachallaun Nov 3, 2023
a315e26
Refactor document store to not use ETS
zachallaun Nov 3, 2023
3126b94
Refactor document store derivation tests
zachallaun Nov 3, 2023
8d7fb81
Cache analysis in document store and integrate with indexer
zachallaun Nov 3, 2023
f48c3eb
Refactor derived document values based on feedback
zachallaun Nov 4, 2023
f0afa92
Transition `Lexical.Ast` APIs to primarily use `%Analysis{}`
zachallaun Nov 6, 2023
d638b91
Add note about analysis to `Ast` moduledoc
zachallaun Nov 6, 2023
5f75b35
Bump sourceror to 0.14.1
zachallaun Nov 6, 2023
5161497
Fix alias analysis when using warn option
zachallaun Nov 8, 2023
b877c33
Revert Makefile changes
zachallaun Nov 8, 2023
5c872e3
Validate document store derivation funs on init
zachallaun Nov 8, 2023
b9624db
Refactor env and completions to use analysis
zachallaun Nov 16, 2023
4c16c0a
Changes from PR feedback
zachallaun Nov 16, 2023
561a39b
Remove unneeded analysis aliases_at tests
zachallaun Nov 16, 2023
543f428
More descriptive name for private fn
zachallaun Nov 16, 2023
f764517
Fix match error in entity resolution
zachallaun Nov 16, 2023
bc06440
Use constructor fn instead of struct literal
zachallaun Nov 16, 2023
ac1fac0
Rename analyze_to to reanalyze_to and only accept analysis
zachallaun Nov 16, 2023
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
314 changes: 147 additions & 167 deletions apps/common/lib/lexical/ast.ex

Large diffs are not rendered by default.

318 changes: 0 additions & 318 deletions apps/common/lib/lexical/ast/aliases.ex

This file was deleted.

66 changes: 66 additions & 0 deletions apps/common/lib/lexical/ast/analysis.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
defmodule Lexical.Ast.Analysis do
@moduledoc """
A data structure representing an analyzed AST.

See `Lexical.Ast.analyze/1`.
"""

alias Lexical.Ast.Analysis.Analyzer
alias Lexical.Document
alias Lexical.Document.Position
alias Lexical.Document.Range

defstruct [:ast, :document, :parse_error, scopes: [], valid?: true]

@type t :: %__MODULE__{}

@doc false
def new(parse_result, document)

def new({:ok, ast}, %Document{} = document) do
scopes = Analyzer.traverse(ast, document)

%__MODULE__{
ast: ast,
document: document,
scopes: scopes
}
end

def new(error, document) do
%__MODULE__{
document: document,
parse_error: error,
valid?: false
}
end

@doc false
def aliases_at(%__MODULE__{} = analysis, %Position{} = position) do
case scopes_at(analysis, position) do
[%Analyzer.Scope{} = scope | _] ->
scope
|> Analyzer.Scope.alias_map(position)
|> Map.new(fn {as, %Analyzer.Alias{} = alias} ->
{as, Analyzer.Alias.to_module(alias)}
end)

[] ->
%{}
end
end

defp scopes_at(%__MODULE__{scopes: scopes}, %Position{} = position) do
scopes
|> Enum.filter(fn %Analyzer.Scope{range: range} = scope ->
scope.id == :global or Range.contains?(range, position)
end)
|> Enum.sort_by(
fn
%Analyzer.Scope{id: :global} -> 0
%Analyzer.Scope{range: range} -> {range.start.line, range.start.character}
end,
:desc
)
end
end
Loading
Loading