Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the addition and deletion of Miscellaneous files to the Buffer Manager #1277

Merged
merged 8 commits into from
Aug 28, 2018

Conversation

akshita31
Copy link
Contributor

@akshita31 akshita31 commented Aug 24, 2018

Addresses: #1252 (comment)

When the buffer manager adds a transient document, if it is unable to associate the document with any project then the buffer manager will add it as a misc file document.
Doing this will avoid the dependency between the order of execution by the file system watcher listeners, that was introduced when we added the misc files systems.

Also added the filesystem watcher to teh buffer manager so it keeps watching the misc files it added hence can handle the deletion of the same

Known bug: There will be no more code to handle the deletion of these files, hence the diagnostics wont disappear if a misc file is deleted, and in vscode if the user clicks on the diagnostics then we will get the file not found error . Edit: Resolved with using the FileSystemWatcher in the Buffer manager

image. Example:

@@ -128,32 +128,35 @@ private bool TryAddTransientDocument(string fileName, string fileContent)
var projects = FindProjectsByFileName(fileName);
if (!projects.Any())
{
return false;
//todo: deal with the deletion of the misc files
_workspace.TryAddMiscellaneousDocument(fileName, LanguageNames.CSharp);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at the OnWorkspaceChanged handler in this class--you'll want to augment it to remove misc files the way we remove transient documents when they are deleted.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This will fix the bug you mentioned)

}

[Fact]
public async Task Returns_only_syntactic_diagnotics()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect us to still have these tests?

Copy link

@rchande rchande left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, couple of small changes

//todo: deal with the deletion of the misc files
if (fileName.EndsWith(".cs") && _workspace.TryAddMiscellaneousDocument(fileName, LanguageNames.CSharp) != null)
{
_fileSystemWatcher.Watch(fileName, OnMiscFileChanged);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you store the OnMiscFileChanged delegate in a field so we don't have to create one instance for every file we watch?

@@ -128,37 +131,54 @@ private bool TryAddTransientDocument(string fileName, string fileContent)
var projects = FindProjectsByFileName(fileName);
if (!projects.Any())
{
//todo: deal with the deletion of the misc files
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is done? :)

}

return true;
}

private void OnMiscFileChanged(string filePath, FileChangeType changeType)
{
if(changeType == FileChangeType.Unspecified && !File.Exists(filePath) || changeType == FileChangeType.Delete)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space

@akshita31
Copy link
Contributor Author

@DustinCampbell Does this seem fine ?

@akshita31 akshita31 changed the title Add the addition of Miscellaneous files to the Buffer Manager Add the addition and deletion of Miscellaneous files to the Buffer Manager Aug 28, 2018
Copy link
Member

@david-driscoll david-driscoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes make sense to me!

@@ -128,37 +133,53 @@ private bool TryAddTransientDocument(string fileName, string fileContent)
var projects = FindProjectsByFileName(fileName);
if (!projects.Any())
{
if (fileName.EndsWith(".cs") && _workspace.TryAddMiscellaneousDocument(fileName, LanguageNames.CSharp) != null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to say something about adding .csx here but they have different project rules anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be doing a case-insensitive EndsWith here to ensure that we also catch .CS.

@david-driscoll david-driscoll merged commit ed12fc8 into OmniSharp:master Aug 28, 2018
Copy link
Contributor

@DustinCampbell DustinCampbell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@@ -128,37 +133,53 @@ private bool TryAddTransientDocument(string fileName, string fileContent)
var projects = FindProjectsByFileName(fileName);
if (!projects.Any())
{
if (fileName.EndsWith(".cs") && _workspace.TryAddMiscellaneousDocument(fileName, LanguageNames.CSharp) != null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be doing a case-insensitive EndsWith here to ensure that we also catch .CS.

@akshita31 akshita31 deleted the buffer_manager_misc branch August 28, 2018 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants