From 9cf4a72d276572a86a46139ef29efa8fbe84f477 Mon Sep 17 00:00:00 2001 From: Minh-Tam TRAN Date: Sun, 17 Sep 2023 16:33:38 +0200 Subject: [PATCH 1/2] Receive information that a project was loaded MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 💌 Motivation: `OmniSharpReloadProject` throws because it does not find key `job.projects_loaded` --- autoload/OmniSharp/actions/workspace.vim | 6 ++++- autoload/OmniSharp/project.vim | 32 +++++++++++++++--------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/autoload/OmniSharp/actions/workspace.vim b/autoload/OmniSharp/actions/workspace.vim index 4cad4ae21..58afc9c59 100644 --- a/autoload/OmniSharp/actions/workspace.vim +++ b/autoload/OmniSharp/actions/workspace.vim @@ -22,9 +22,13 @@ function! s:ProjectsRH(job, response) abort " If no projects have been loaded by the time this callback is reached, there " are no projects and the job can be marked as ready let projects = get(get(a:response.Body, 'MsBuild', {}), 'Projects', {}) + + let a:job.projects_total = max([ get(a:job, 'projects_total', 0), len(projects) ]) + let a:job.projects_loaded = get(a:job, 'projects_loaded', 0) let a:job.projects = map(projects, \ {_,project -> {"name": project.AssemblyName, "path": project.Path, "target": project.TargetPath}}) - if get(a:job, 'projects_total', 0) > 0 + + if a:job.projects_total > 0 call OmniSharp#log#Log(a:job, 'Workspace complete: ' . a:job.projects_total . ' project(s)') else call OmniSharp#log#Log(a:job, 'Workspace complete: no projects') diff --git a/autoload/OmniSharp/project.vim b/autoload/OmniSharp/project.vim index 24b864c64..3d754e0e6 100644 --- a/autoload/OmniSharp/project.vim +++ b/autoload/OmniSharp/project.vim @@ -72,22 +72,30 @@ function! OmniSharp#project#ParseEvent(job, event, eventBody) abort let a:job.projects_total = len(a:job.loading) silent doautocmd User OmniSharpProjectUpdated endif - endif - if message =~# '^Successfully loaded project' - \ || message =~# '^Failed to load project' + elseif message =~# '^Successfully loaded project' || message =~# '^Failed to load project' if message[0] ==# 'F' echom 'Failed to load project: ' . project endif - call filter(a:job.loading, {idx,val -> val !=# project}) - let a:job.projects_loaded = projects_loaded + 1 - silent doautocmd User OmniSharpProjectUpdated - if len(a:job.loading) == 0 - call OmniSharp#project#RegisterLoaded(a:job) - unlet a:job.loading - call timer_stop(a:job.loading_timeout) - unlet a:job.loading_timeout - endif + call s:AcknowledgeLoadedProject(a:job, project) endif + elseif a:event ==# 'MsBuildProjectDiagnostics' + let project = a:eventBody.FileName + call s:AcknowledgeLoadedProject(a:job, project) + endif +endfunction + +function! s:AcknowledgeLoadedProject(job, project) + if index(a:job.loading, a:project) < 0 + return + endif + call filter(a:job.loading, {idx,val -> val !=# a:project}) + let a:job.projects_loaded = get(a:job, 'projects_loaded', 0) + 1 + silent doautocmd User OmniSharpProjectUpdated + if empty(a:job.loading) + call OmniSharp#project#RegisterLoaded(a:job) + unlet a:job.loading + call timer_stop(a:job.loading_timeout) + unlet a:job.loading_timeout endif endfunction From 18437fb9663a34172698789b58ca3aca030ea8aa Mon Sep 17 00:00:00 2001 From: Minh-Tam TRAN Date: Mon, 25 Sep 2023 21:48:38 +0200 Subject: [PATCH 2/2] Improve discrimination between `OmniSharpStartServer` project load responses and `OmniSharpReloadProject` project load responses --- autoload/OmniSharp/project.vim | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/autoload/OmniSharp/project.vim b/autoload/OmniSharp/project.vim index 3d754e0e6..b98feb7c7 100644 --- a/autoload/OmniSharp/project.vim +++ b/autoload/OmniSharp/project.vim @@ -78,16 +78,13 @@ function! OmniSharp#project#ParseEvent(job, event, eventBody) abort endif call s:AcknowledgeLoadedProject(a:job, project) endif - elseif a:event ==# 'MsBuildProjectDiagnostics' + elseif has_key(a:job, 'restart_time') && a:event ==# 'MsBuildProjectDiagnostics' let project = a:eventBody.FileName call s:AcknowledgeLoadedProject(a:job, project) endif endfunction function! s:AcknowledgeLoadedProject(job, project) - if index(a:job.loading, a:project) < 0 - return - endif call filter(a:job.loading, {idx,val -> val !=# a:project}) let a:job.projects_loaded = get(a:job, 'projects_loaded', 0) + 1 silent doautocmd User OmniSharpProjectUpdated