-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: progress messages for workspace indexing (#179)
- Loading branch information
Showing
12 changed files
with
97 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
import Config | ||
|
||
config :next_ls, :indexing_timeout, 100 | ||
|
||
import_config "#{config_env()}.exs" |
This file contains 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 @@ | ||
import Config |
This file contains 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 @@ | ||
import Config |
This file contains 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 @@ | ||
import Config |
This file contains 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 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 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,56 @@ | ||
defmodule NextLS.DB.Activity do | ||
@moduledoc false | ||
@behaviour :gen_statem | ||
|
||
def child_spec(opts) do | ||
%{ | ||
id: opts[:name] || opts[:id], | ||
start: {__MODULE__, :start_link, [opts]} | ||
} | ||
end | ||
|
||
def start_link(args) do | ||
:gen_statem.start_link({:local, Keyword.get(args, :name)}, __MODULE__, Keyword.drop(args, [:name]), []) | ||
end | ||
|
||
def update(statem, count), do: :gen_statem.cast(statem, count) | ||
|
||
@impl :gen_statem | ||
def callback_mode, do: :state_functions | ||
|
||
@impl :gen_statem | ||
def init(args) do | ||
logger = Keyword.fetch!(args, :logger) | ||
lsp = Keyword.fetch!(args, :lsp) | ||
timeout = Keyword.fetch!(args, :timeout) | ||
|
||
{:ok, :waiting, %{count: 0, logger: logger, lsp: lsp, timeout: timeout, token: nil}} | ||
end | ||
|
||
def active(:cast, 0, data) do | ||
{:keep_state, %{data | count: 0}, [{:state_timeout, data.timeout, :waiting}]} | ||
end | ||
|
||
def active(:cast, mailbox_count, %{count: 0} = data) do | ||
{:keep_state, %{data | count: mailbox_count}, [{:state_timeout, :cancel}]} | ||
end | ||
|
||
def active(:cast, mailbox_count, data) do | ||
{:keep_state, %{data | count: mailbox_count}, []} | ||
end | ||
|
||
def active(:state_timeout, :waiting, data) do | ||
NextLS.Progress.stop(data.lsp, data.token, "Finished indexing!") | ||
{:next_state, :waiting, %{data | token: nil}} | ||
end | ||
|
||
def waiting(:cast, 0, _data) do | ||
:keep_state_and_data | ||
end | ||
|
||
def waiting(:cast, mailbox_count, data) do | ||
token = NextLS.Progress.token() | ||
NextLS.Progress.start(data.lsp, token, "Indexing!") | ||
{:next_state, :active, %{data | count: mailbox_count, token: token}} | ||
end | ||
end |
This file contains 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 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 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 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 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