public Task <Unit> Handle(DidChangeWatchedFilesParams request, CancellationToken cancellationToken)
        {
            bool shouldRevalidate = false;

            foreach (var change in request.Changes)
            {
                if (change.Type == FileChangeType.Deleted)
                {
                    TryRemove(PathHelper.GetPathFromFileUri(change.Uri));
                    shouldRevalidate = true;
                }
                else if (change.Type == FileChangeType.Created)
                {
                    TryAdd(PathHelper.GetPathFromFileUri(change.Uri));
                    shouldRevalidate = true;
                }
            }

            if (shouldRevalidate)
            {
                Validate();
            }

            return(Unit.Task);
        }
Пример #2
0
 public override Task <Unit> Handle(DidChangeWatchedFilesParams request, CancellationToken cancellationToken)
 {
     foreach (var change in request.Changes)
     {
         var changeType = change switch
         {
             { Type : FileChangeType.Changed } => FileWatching.FileChangeType.Change,
 public void DidChangeWatchedFiles(DidChangeWatchedFilesParams @params)
 {
     _disposableBag.ThrowIfDisposed();
     foreach (var c in @params.changes.MaybeEnumerate())
     {
         switch (c.type)
         {
         case FileChangeType.Deleted:
             _interpreter.ModuleResolution.CurrentPathResolver.RemoveModulePath(c.uri.ToAbsolutePath());
             break;
         }
     }
 }
Пример #4
0
        public async Task <Unit> Handle(DidChangeWatchedFilesParams request, CancellationToken cancellationToken)
        {
            var createdOrDeleted = request.Changes.Where(c => c.Type == FileChangeType.Created || c.Type == FileChangeType.Deleted);

            if (createdOrDeleted.Any(c => Path.GetExtension(c.Uri.ToFilePath()).CaseInsensitiveEquals(".psc")))
            {
                await UpdateProjects(UpdateProjectsOptions.ReloadProjects);
            }
            else if (createdOrDeleted.Any(c => Path.GetExtension(c.Uri.ToFilePath()).CaseInsensitiveEquals(".psc")))
            {
                await UpdateProjects(UpdateProjectsOptions.ResolveExistingProjectSources);
            }

            return(Unit.Value);
        }
        public Task <Unit> Handle(DidChangeWatchedFilesParams request, CancellationToken cancellationToken)
        {
            foreach (var change in request.Changes)
            {
                string localPath;
                try
                {
                    localPath = change.Uri.ToUri().LocalPath;
                }
                catch
                {
                    continue; // this is invalid path
                }

                if (localPath?.EndsWith(".csproj") == true)
                {
                    if (change.Type == FileChangeType.Created)
                    {
                        _projectShepard.ProjectAdded(localPath);
                    }
                    else if (change.Type == FileChangeType.Deleted)
                    {
                        _projectShepard.ProjectRemoved(localPath);
                    }
                }
                if (localPath?.EndsWith(".dll") == true)
                {
                    string name     = Path.GetFileNameWithoutExtension(localPath);
                    var    projects = _projectShepard.GetProjectsByName(name);
                    if (projects.Count > 0)
                    {
                        string directory = Path.GetDirectoryName(localPath);
                        foreach (var project in projects)
                        {
                            if (directory.StartsWith(project.BinariesDirectory))
                            {
                                _metadataShepard.InvalidateMetadata(project.FilePath);
                                project.UpdateDll(localPath);
                            }
                        }
                    }
                }
            }

            return(Unit.Task);
        }
        public void SimpleTest(string expected)
        {
            var model = new DidChangeWatchedFilesParams {
                Changes = new[] {
                    new FileEvent {
                        Type = FileChangeType.Created,
                        Uri  = new Uri("file:///someawesomefile")
                    }
                }
            };
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

            var deresult = new LspSerializer(ClientVersion.Lsp3).DeserializeObject <DidChangeWatchedFilesParams>(expected);

            deresult.Should().BeEquivalentTo(model);
        }
        public override Task <Unit> Handle(DidChangeWatchedFilesParams request, CancellationToken cancellationToken)
        {
            Container <FileEvent>   fileEvents = request.Changes;
            IEnumerable <FileEvent> bicepConfigFileChangeEvents = fileEvents.Where(x => string.Equals(Path.GetFileName(x.Uri.Path),
                                                                                                      LanguageConstants.BicepConfigurationFileName,
                                                                                                      StringComparison.OrdinalIgnoreCase));

            // Refresh compilation of source files in workspace when local bicepconfig.json file is created, deleted or changed
            if (bicepConfigFileChangeEvents.Any())
            {
                Uri uri = bicepConfigFileChangeEvents.First().Uri.ToUri();
                bicepConfigChangeHandler.RefreshCompilationOfSourceFilesInWorkspace();
            }

            compilationManager.HandleFileChanges(fileEvents);

            return(Unit.Task);
        }
        public void NonStandardCharactersTest(string expected)
        {
            var model = new DidChangeWatchedFilesParams {
                Changes = new[] {
                    new FileEvent {
                        Type = FileChangeType.Created,
                        // Mörkö
                        Uri = new Uri("file:///M%C3%B6rk%C3%B6.cs")
                    }
                }
            };
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

            var deresult = new LspSerializer(ClientVersion.Lsp3).DeserializeObject <DidChangeWatchedFilesParams>(expected);

            deresult.Should().BeEquivalentTo(model);
        }
Пример #9
0
        public override async Task DidChangeWatchedFiles(DidChangeWatchedFilesParams @params, CancellationToken token)
        {
            foreach (var c in @params.changes.MaybeEnumerate())
            {
                _disposableBag.ThrowIfDisposed();
                IProjectEntry entry;
                switch (c.type)
                {
                case FileChangeType.Created:
                    entry = await LoadFileAsync(c.uri);

                    if (entry != null)
                    {
                        TraceMessage($"Saw {c.uri} created and loaded new entry");
                    }
                    else
                    {
                        LogMessage(MessageType.Warning, $"Failed to load {c.uri}");
                    }
                    break;

                case FileChangeType.Deleted:
                    await UnloadFileAsync(c.uri);

                    break;

                case FileChangeType.Changed:
                    if ((entry = ProjectFiles.GetEntry(c.uri, false)) is IDocument doc)
                    {
                        // If document version is >=0, it is loaded in memory.
                        if (doc.GetDocumentVersion(0) < 0)
                        {
                            await EnqueueItemAsync(doc, AnalysisPriority.Low);
                        }
                    }
                    break;
                }
            }
        }
Пример #10
0
 public static void DidChangeWatchedFiles(this ILanguageClientWorkspace router, DidChangeWatchedFilesParams @params)
 {
     router.SendNotification(WorkspaceNames.DidChangeWatchedFiles, @params);
 }
Пример #11
0
 protected override void DidChangeWatchedFiles(DidChangeWatchedFilesParams @params)
 {
     base.DidChangeWatchedFiles(@params);
 }
 public virtual Task DidChangeWatchedFiles(DidChangeWatchedFilesParams @params, CancellationToken cancellationToken)
 => Task.CompletedTask;
Пример #13
0
 public Task <Unit> Handle(DidChangeWatchedFilesParams request, CancellationToken cancellationToken) => Unit.Task;
Пример #14
0
 public abstract RpcResult DidChangeWatchedFiles(DidChangeWatchedFilesParams args);
        public override Task <Unit> Handle(DidChangeWatchedFilesParams request, CancellationToken cancellationToken)
        {
            compilationManager.HandleFileChanges(request.Changes);

            return(Unit.Task);
        }
Пример #16
0
 public Task <Unit> Handle(DidChangeWatchedFilesParams request, CancellationToken cancellationToken)
 {
     _log.LogInformation(string.Format(Resources.LoggingMessages.request_handle, _method));
     return(Unit.Task);
 }
Пример #17
0
 public override Task <Unit> Handle(DidChangeWatchedFilesParams request, CancellationToken cancellationToken) => _handler.Invoke(request, cancellationToken);
Пример #18
0
 public abstract Task <Unit> Handle(DidChangeWatchedFilesParams request, CancellationToken cancellationToken);
Пример #19
0
 private async Task ProcessFileChangesAsync(DidChangeWatchedFilesParams changeWatchedParams)
 {
     // We now watch only .msbuildproj and project.assets.json files, forcing us to reload the project
     await TryReloadProjectAsync();
 }
Пример #20
0
        private async Task OnFileChanged(object sender, System.IO.FileSystemEventArgs e)
        {
            // Skip directory change events and when rpc has ben disconnected
            if (!e.IsDirectoryChanged() && _rpc != null)
            {
                // Create something to match with
                var item = new InMemoryDirectoryInfo(_root, new string[] { e.FullPath });

                // See if this matches one of our patterns.
                if (_matcher.Execute(item).HasMatches)
                {
                    // Send out the event to the language server
                    var renamedArgs     = e as System.IO.RenamedEventArgs;
                    var didChangeParams = new DidChangeWatchedFilesParams();

                    // Visual Studio actually does a rename when saving. The rename is from a file ending with '~'
                    if (renamedArgs == null || renamedArgs.OldFullPath.EndsWith("~"))
                    {
                        renamedArgs                    = null;
                        didChangeParams.Changes        = new FileEvent[] { new FileEvent() };
                        didChangeParams.Changes[0].Uri = new Uri(e.FullPath);

                        switch (e.ChangeType)
                        {
                        case WatcherChangeTypes.Created:
                            didChangeParams.Changes[0].FileChangeType = FileChangeType.Created;
                            break;

                        case WatcherChangeTypes.Deleted:
                            didChangeParams.Changes[0].FileChangeType = FileChangeType.Deleted;
                            break;

                        case WatcherChangeTypes.Changed:
                            didChangeParams.Changes[0].FileChangeType = FileChangeType.Changed;
                            break;

                        case WatcherChangeTypes.Renamed:
                            didChangeParams.Changes[0].FileChangeType = FileChangeType.Changed;
                            break;

                        default:
                            didChangeParams.Changes = Array.Empty <FileEvent>();
                            break;
                        }
                    }
                    else
                    {
                        // file renamed
                        var deleteEvent = new FileEvent();
                        deleteEvent.FileChangeType = FileChangeType.Deleted;
                        deleteEvent.Uri            = new Uri(renamedArgs.OldFullPath);

                        var createEvent = new FileEvent();
                        createEvent.FileChangeType = FileChangeType.Created;
                        createEvent.Uri            = new Uri(renamedArgs.FullPath);

                        didChangeParams.Changes = new FileEvent[] { deleteEvent, createEvent };
                    }

                    if (didChangeParams.Changes.Any())
                    {
                        await _rpc.NotifyWithParameterObjectAsync(Methods.WorkspaceDidChangeWatchedFiles.Name, didChangeParams);

                        if (renamedArgs != null)
                        {
                            var textDocumentIdentifier = new TextDocumentIdentifier();
                            textDocumentIdentifier.Uri = new Uri(renamedArgs.OldFullPath);

                            var closeParam = new DidCloseTextDocumentParams();
                            closeParam.TextDocument = textDocumentIdentifier;

                            await _rpc.NotifyWithParameterObjectAsync(Methods.TextDocumentDidClose.Name, closeParam);

                            var textDocumentItem = new TextDocumentItem();
                            textDocumentItem.Uri = new Uri(renamedArgs.FullPath);

                            var openParam = new DidOpenTextDocumentParams();
                            openParam.TextDocument = textDocumentItem;
                            await _rpc.NotifyWithParameterObjectAsync(Methods.TextDocumentDidOpen.Name, openParam);
                        }
                    }
                }
            }
        }
Пример #21
0
 protected override void DidChangeWatchedFiles(DidChangeWatchedFilesParams @params)
 {
     Logger.Instance.Log("We received an file change event");
 }