Skip to content

Commit

Permalink
Fix for NRE in VS (#1087)
Browse files Browse the repository at this point in the history
* Fix for NRE in VS

* formatting
  • Loading branch information
belav authored Dec 22, 2023
1 parent 500e4c2 commit 74d4525
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="83d6b6a0-9e25-4034-80f3-38445d8a8837" Version="1.5.0" Language="en-US" Publisher="CSharpier" />
<Identity Id="83d6b6a0-9e25-4034-80f3-38445d8a8837" Version="1.5.1" Language="en-US" Publisher="CSharpier" />
<DisplayName>CSharpier</DisplayName>
<Description xml:space="preserve">CSharpier is an opinionated code formatter for c#. It uses Roslyn to parse your code and re-prints it using its own rules.</Description>
<MoreInfo>https://github.com/belav/csharpier</MoreInfo>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="edd8b38c-baa1-46c6-b82e-1da7a0ba597b" Version="1.5.0" Language="en-US" Publisher="CSharpier" />
<Identity Id="edd8b38c-baa1-46c6-b82e-1da7a0ba597b" Version="1.5.1" Language="en-US" Publisher="CSharpier" />
<DisplayName>CSharpier 2019</DisplayName>
<Description xml:space="preserve">CSharpier is an opinionated code formatter for c#. It uses Roslyn to parse your code and re-prints it using its own rules.</Description>
<MoreInfo>https://github.com/belav/csharpier</MoreInfo>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ public void Format(Document document)
}

public bool ProcessSupportsFormatting(Document document) =>
!(
this.cSharpierProcessProvider.GetProcessFor(document.FullName)
is NullCSharpierProcess
);
this.cSharpierProcessProvider.GetProcessFor(document.FullName)
is not NullCSharpierProcess;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ public void ShowInfoBar(string message, IEnumerable<InfoBarActionButton>? button
}

var actions = (buttons ?? Enumerable.Empty<InfoBarActionButton>())
.Select(o => o.IsHyperLink ? new InfoBarHyperlink(o.Text, o.Context) as InfoBarActionItem : new InfoBarButton(o.Text, o.Context))
.Select(
o =>
o.IsHyperLink
? new InfoBarHyperlink(o.Text, o.Context) as InfoBarActionItem
: new InfoBarButton(o.Text, o.Context)
)
.ToArray();
var infoBarModel = new InfoBarModel(
spans,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static async Task InitializeAsync(CSharpierPackage package)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
var dte = await package.GetServiceAsync(typeof(DTE)) as DTE;
new ReformatWithCSharpierOnSave(package, dte!);
_ = new ReformatWithCSharpierOnSave(package, dte!);
}

public int OnBeforeSave(uint docCookie)
Expand Down Expand Up @@ -73,20 +73,17 @@ public int OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowF
return VSConstants.S_OK;
}

private Document FindDocument(uint docCookie)
private Document? FindDocument(uint docCookie)
{
try
{
ThreadHelper.ThrowIfNotOnUIThread();
var documentInfo = this.runningDocumentTable.GetDocumentInfo(docCookie);
var documentPath = documentInfo.Moniker;

if (this.dte.ActiveDocument.FullName == documentPath)
{
return this.dte.ActiveDocument;
}

return this.dte.Documents.Item(documentPath);
return this.dte.ActiveDocument?.FullName == documentPath
? this.dte.ActiveDocument
: this.dte.Documents?.Item(documentPath);
}
catch (Exception ex)
{
Expand Down
5 changes: 4 additions & 1 deletion Src/CSharpier.VisualStudio/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## [1.5.0]
## [1.5.1]
- Fix for occasional NRE

## [1.5.0]
- Fix issues with using 0.26.X
- Better error handling and logging

Expand Down

0 comments on commit 74d4525

Please sign in to comment.