Skip to content

Commit 5d990e8

Browse files
authored
WI #2011 Add -now --nowatchers options (#2013)
* WI #2011 Add -now --nowatchers options * WI #2011 Change review
1 parent e0d65ad commit 5d990e8

File tree

4 files changed

+48
-16
lines changed

4 files changed

+48
-16
lines changed

TypeCobol.LanguageServer/TypeCobolCustomLanguageServer/TypeCobolCustomLanguageServer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ private void ReceivedSignatureHelpContext(NotificationType notificationType, obj
124124

125125
/// <summary>
126126
/// The Missing copies notification is sent from the client to the server
127-
/// when the client failed to load copies, it send back a list of missing copies to the server.
127+
/// when the client has finished to load copies, it send back a list of missing copies that it fails to load to the server.
128+
/// The list can be empty if all copies has been loaded.
128129
/// </summary>
129130
protected virtual void OnDidReceiveMissingCopies(MissingCopiesParams parameter)
130131
{

TypeCobol.LanguageServer/TypeCobolServer.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ public TypeCobolServer(IRPCServer rpcServer, Queue<MessageActionWrapper> message
7979
/// </summary>
8080
public List<string> CustomAnalyzerFiles { get; set; }
8181

82+
/// <summary>
83+
/// No Copy and Dependency files watchers.
84+
/// </summary>
85+
public bool NoCopyDependencyWatchers { get; set; }
86+
8287
private bool Logger(string message, Uri uri)
8388
{
8489
if (uri == null)
@@ -238,6 +243,8 @@ protected override InitializeResult OnInitialize(InitializeParams parameters)
238243

239244
// Initialize the workspace.
240245
this.Workspace = new Workspace(rootDirectory.FullName, workspaceName, _messagesActionsQueue, Logger);
246+
if (!NoCopyDependencyWatchers)
247+
this.Workspace.InitCopyDependencyWatchers();
241248
#if EUROINFO_RULES
242249
this.Workspace.CpyCopyNamesMapFilePath = CpyCopyNamesMapFilePath;
243250
#endif

TypeCobol.LanguageServer/TypeCobolServerHost.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ public static string Version
121121
/// </summary>
122122
public static bool UseOutlineRefresh { get; set; }
123123

124+
/// <summary>
125+
/// No Copy and Dependency files watchers.
126+
/// </summary>
127+
public static bool NoCopyDependencyWatchers { get; set; }
128+
124129
#if EUROINFO_RULES
125130
/// <summary>
126131
/// A Path to a file of CPY Copy names
@@ -233,7 +238,8 @@ static int Main(string[] args)
233238
{ "cfg=", "{dot output mode} Control Flow Graph support and Dot Output mode: No/0, AsFile/1 or AsContent/2.",
234239
(String m) => {TypeCobolCustomLanguageServer.UseCfgMode ucm = TypeCobolCustomLanguageServer.UseCfgMode.No;
235240
Enum.TryParse(m, out ucm); UseCfg = ucm; } },
236-
{ "ca|customanalyzer=", "{PATH} to a custom DLL file containing code analyzers. This option can be specified more than once.", v => CustomAnalyzerFiles.Add(v) }
241+
{ "ca|customanalyzer=", "{PATH} to a custom DLL file containing code analyzers. This option can be specified more than once.", v => CustomAnalyzerFiles.Add(v) },
242+
{ "now|nowatchers", "No Copy and Dependency files watchers.", _ => NoCopyDependencyWatchers = true}
237243
};
238244

239245
System.Collections.Generic.List<string> arguments;
@@ -312,6 +318,7 @@ static int Main(string[] args)
312318
typeCobolServer.UseOutlineRefresh = UseOutlineRefresh;
313319
typeCobolServer.UseCfgDfaDataRefresh = UseCfg;
314320
typeCobolServer.CustomAnalyzerFiles = CustomAnalyzerFiles;
321+
typeCobolServer.NoCopyDependencyWatchers = NoCopyDependencyWatchers;
315322
#if EUROINFO_RULES
316323
typeCobolServer.CpyCopyNamesMapFilePath = CpyCopyNamesMapFilePath;
317324
#endif

TypeCobol.LanguageServer/Workspace.cs

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ public bool IsEmpty
155155
}
156156
}
157157
}
158-
159158
#endregion
160159

161160
public Workspace(string rootDirectoryFullName, string workspaceName, Queue<MessageActionWrapper> messagesActionsQueue, Func<string, Uri, bool> logger)
@@ -179,10 +178,12 @@ public Workspace(string rootDirectoryFullName, string workspaceName, Queue<Messa
179178
this.CompilationProject.CompilationOptions.UseEuroInformationLegacyReplacingSyntax =
180179
this.CompilationProject.CompilationOptions.UseEuroInformationLegacyReplacingSyntax ||
181180
UseEuroInformationLegacyReplacingSyntax;
181+
}
182182

183+
internal void InitCopyDependencyWatchers()
184+
{
183185
// Create the refresh action that will be used by file watchers
184186
Action refreshAction = RefreshOpenedFiles;
185-
186187
_DepWatcher = new DependenciesFileWatcher(this, refreshAction);
187188
_CopyWatcher = new CopyWatcher(this, refreshAction);
188189
}
@@ -581,26 +582,42 @@ public void DidChangeConfigurationParams(string[] arguments)
581582
else
582583
RefreshCustomSymbols();
583584

584-
//Dispose previous watcher before setting new ones
585-
_DepWatcher.Dispose();
586-
_CopyWatcher.Dispose();
587-
foreach (var depFolder in Configuration.CopyFolders)
585+
//Dispose previous watchers before setting new ones
586+
if (_CopyWatcher != null)
588587
{
589-
_CopyWatcher.SetDirectoryWatcher(depFolder);
590-
}
591-
foreach (var depFolder in Configuration.Dependencies)
592-
{
593-
_DepWatcher.SetDirectoryWatcher(depFolder);
588+
_CopyWatcher.Dispose();
589+
foreach (var copyFolder in Configuration.CopyFolders)
590+
{
591+
_CopyWatcher.SetDirectoryWatcher(copyFolder);
592+
}
594593
}
595-
foreach (var intrinsicFolder in Configuration.Copies)
594+
if (_DepWatcher != null)
596595
{
597-
_DepWatcher.SetDirectoryWatcher(intrinsicFolder);
596+
_DepWatcher.Dispose();
597+
foreach (var depFolder in Configuration.Dependencies)
598+
{
599+
_DepWatcher.SetDirectoryWatcher(depFolder);
600+
}
601+
foreach (var intrinsicFolder in Configuration.Copies)
602+
{
603+
_DepWatcher.SetDirectoryWatcher(intrinsicFolder);
604+
}
598605
}
599606
}
600607

608+
/// <summary>
609+
/// The method is called in response to a MissingCopyNotification from the client.
610+
/// The RemainingMissingCopies list can contain a list of COPY that the client fails to load,
611+
/// or an empty list if all COPY have been loaded.
612+
/// </summary>
613+
/// <param name="fileUri">Uri of the document from wich the response is emitted</param>
614+
/// <param name="RemainingMissingCopies">The list of unloaded COPY if any, an empty list otherwise</param>
601615
public void UpdateMissingCopies(Uri fileUri, List<string> RemainingMissingCopies)
602616
{
603-
//TODO remove client to server notification properly.
617+
if (_CopyWatcher == null)
618+
{// No Copy Watcher ==> Refresh ourself opened file.
619+
RefreshOpenedFiles();
620+
}
604621
}
605622

606623
/// <summary>

0 commit comments

Comments
 (0)