Skip to content

Commit

Permalink
refactor: move token function to progress module (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanberg authored Aug 13, 2023
1 parent 88e5561 commit 4362d66
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
15 changes: 4 additions & 11 deletions lib/next_ls.ex
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ defmodule NextLS do
GenLSP.log(lsp, "[NextLS] Booting runtimes...")

for %{uri: uri, name: name} <- lsp.assigns.workspace_folders do
token = token()
token = Progress.token()
Progress.start(lsp, token, "Initializing NextLS runtime for folder #{name}...")
parent = self()
working_dir = URI.parse(uri).path
Expand Down Expand Up @@ -417,7 +417,7 @@ defmodule NextLS do
refresh_refs =
dispatch(lsp.assigns.registry, :runtimes, fn entries ->
for {pid, %{name: name, uri: wuri, db: db}} <- entries, String.starts_with?(uri, wuri), into: %{} do
token = token()
token = Progress.token()
Progress.start(lsp, token, "Compiling...")

task =
Expand Down Expand Up @@ -479,7 +479,7 @@ defmodule NextLS do

for %{name: name, uri: uri} <- added, name not in names do
GenLSP.log(lsp, "[NextLS] Adding workspace folder #{name}")
token = token()
token = Progress.token()
Progress.start(lsp, token, "Initializing NextLS runtime for folder #{name}...")
parent = self()
working_dir = URI.parse(uri).path
Expand Down Expand Up @@ -590,7 +590,7 @@ defmodule NextLS do
end

def handle_info({:runtime_ready, name, runtime_pid}, lsp) do
token = token()
token = Progress.token()
Progress.start(lsp, token, "Compiling...")

task =
Expand Down Expand Up @@ -626,13 +626,6 @@ defmodule NextLS do
{:noreply, lsp}
end

defp token do
8
|> :crypto.strong_rand_bytes()
|> Base.url_encode64(padding: false)
|> binary_part(0, 8)
end

defp version do
case :application.get_key(:next_ls, :vsn) do
{:ok, version} -> to_string(version)
Expand Down
7 changes: 7 additions & 0 deletions lib/next_ls/progress.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,11 @@ defmodule NextLS.Progress do
}
})
end

def token do
8
|> :crypto.strong_rand_bytes()
|> Base.url_encode64(padding: false)
|> binary_part(0, 8)
end
end

0 comments on commit 4362d66

Please sign in to comment.