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

Update samples for VS 17.13 #431

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
bf51da3
Update samples for VS 17.9 GA
Jan 26, 2024
945c9dd
Update samples for VS 17.10
Jan 26, 2024
3bd5960
Update packages
Feb 7, 2024
78c6695
Merge branch 'main' into preview_17.10
Feb 7, 2024
8b0f186
Update package versions
Feb 23, 2024
0e17757
Update packages
Feb 28, 2024
798a5dc
Update packages
Mar 19, 2024
3ebe89d
Update packages
Mar 26, 2024
46ee9e1
Add testing of xaml resources
Mar 29, 2024
efe9682
Update packages for 17.11
May 9, 2024
16b89f9
Merge remote-tracking branch 'remotes/origin/main' into preview_17.11
May 22, 2024
50be2b5
Update packages
May 22, 2024
4b8ea58
Update packages to 17.11.232 to remove dependency on ServiceHub.Exten…
BertanAygun Jun 3, 2024
98193af
Add samples for tool window toolbar and context menu
Jun 4, 2024
5a55300
Fix
Jun 5, 2024
0b648b4
Update usage of Image control
Jun 11, 2024
49f6e9c
Updating packages
Jun 14, 2024
be0aa2d
Unified getting querySpace and fixed wording
Jxwoon Jun 26, 2024
754e045
Merge pull request #399 from microsoft/dev/jasminewoon/17.11_Updates
Jxwoon Jul 2, 2024
2d1a43b
Update packages
Jul 8, 2024
d35d73d
Update packages
Jul 9, 2024
ed16717
Avoid warnings
Jul 9, 2024
481a824
Fix warnings
Jul 9, 2024
7e0956b
Adding a test for settings
Jul 9, 2024
d705a3f
Adding a test for the new Image control
Jul 9, 2024
0a2e66a
Merge branch 'preview_17.11' into preview_17.12
Jul 10, 2024
48ee411
Update packages
Jul 10, 2024
e268bc6
Update packages
Aug 8, 2024
4232f23
Merge remote-tracking branch 'remotes/origin/main' into preview_17.12
Aug 13, 2024
d0f83ee
Update packages
Sep 6, 2024
8d87089
Update packages
Sep 25, 2024
c66d69f
Merge remote-tracking branch 'remotes/origin/main' into preview_17.12
Sep 25, 2024
2b4d75f
Add missing project to solution
Sep 25, 2024
6a8cc52
Updating packages
Oct 4, 2024
139c1ed
Update packages
Oct 11, 2024
16084eb
Fix
Oct 11, 2024
84abce4
Update packages
Nov 5, 2024
27ad5b2
Update packages
Nov 12, 2024
fc5e7ff
Merge from main for 17.12
Nov 13, 2024
f9d4aaa
Use new event in visualizers
Nov 18, 2024
7472bf7
Merge remote-tracking branch 'origin/main' into preview_17.13
Nov 18, 2024
0c8590d
Taggers and CodeLens manual tests
Nov 22, 2024
ec61954
Update packages
Nov 22, 2024
f31ecc0
Update packages
Dec 11, 2024
967b4f1
Update the settings sample to use generated observers. (#447)
matteo-prosperi Dec 13, 2024
24ae733
Fix readme
Dec 16, 2024
a259e54
Update dependencies
Jan 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Sdk" Version="17.12.40390" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Build" Version="17.12.40390" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Sdk" Version="17.13.39466" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Build" Version="17.13.39466" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Sdk" Version="17.12.40390" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Build" Version="17.12.40390" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Sdk" Version="17.13.39466" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Build" Version="17.13.39466" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Sdk" Version="17.12.40390" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Build" Version="17.12.40390" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Sdk" Version="17.13.39466" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Build" Version="17.13.39466" />
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.6.36389" ExcludeAssets="runtime" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Sdk" Version="17.12.40390" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Build" Version="17.12.40390" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Sdk" Version="17.13.39466" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Build" Version="17.13.39466" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Sdk" Version="17.12.40390" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Build" Version="17.12.40390" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Sdk" Version="17.13.39466" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Build" Version="17.13.39466" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Sdk" Version="17.12.40390" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Build" Version="17.12.40390" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Sdk" Version="17.13.39466" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Build" Version="17.13.39466" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<NeutralLanguage>en-US</NeutralLanguage>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Sdk" Version="17.12.40390" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Build" Version="17.12.40390" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Sdk" Version="17.13.39466" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Build" Version="17.13.39466" />
<PackageReference Include="Microsoft.VisualStudio.LanguageServer.Protocol" Version="17.2.8" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public MainToolWindow()
new LanguageServerTest(this.Extensibility),
new SettingsTest(this.Extensibility),
new ImageTest(this.Extensibility),
new TaggerTest(this.Extensibility),
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if INPROC
namespace InProcFeatureGallery;
#else
namespace FeatureGallery;
#endif

using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using Microsoft.VisualStudio.Extensibility;
using Microsoft.VisualStudio.Extensibility.Editor;

#pragma warning disable VSEXTPREVIEW_CODELENS // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

internal class MarkdownCodeLens : InvokableCodeLens
{
private readonly CodeElement codeElement;

public MarkdownCodeLens(CodeElement codeElement)
{
this.codeElement = codeElement;
}

public override void Dispose()
{
}

public override Task ExecuteAsync(CodeElementContext codeElementContext, IClientContext clientContext, CancellationToken cancelToken)
{
TaskCompletionSource<bool> taskCompletionSource = new();
var thread = new Thread(() =>
{
try
{
Clipboard.SetText(this.codeElement.UniqueIdentifier ?? "Unknown identifier");
taskCompletionSource.SetResult(false);
}
catch (Exception e)
{
taskCompletionSource.SetException(e);
}
});

thread.SetApartmentState(ApartmentState.STA);
thread.Start();

return taskCompletionSource.Task;
}

public override Task<CodeLensLabel> GetLabelAsync(CodeElementContext codeElementContext, CancellationToken token)
{
return Task.FromResult(new CodeLensLabel()
{
Text = this.codeElement.UniqueIdentifier ?? "Unknown identifier",
Tooltip = "Unique identifier of this section, click to copy the identifier to the clipboard",
});
}
}

#pragma warning restore VSEXTPREVIEW_CODELENS // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if INPROC
namespace InProcFeatureGallery;
#else
namespace FeatureGallery;
#endif

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Extensibility;
using Microsoft.VisualStudio.Extensibility.Editor;

#pragma warning disable VSEXTPREVIEW_CODELENS // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

/// <summary>
/// A sample CodeLens provider that shows the number of words in a method or type and provides custom UI when clicked.
/// </summary>
[VisualStudioContribution]
internal class MarkdownCodeLensProvider : ExtensionPart, ICodeLensProvider
{
public TextViewExtensionConfiguration TextViewExtensionConfiguration => new()
{
AppliesTo = [DocumentFilter.FromDocumentType(TaggerTest.MyMarkdownDocumentType)],
};

#pragma warning disable CEE0027 // String not localized
public CodeLensProviderConfiguration CodeLensProviderConfiguration =>
new("Remote UI CodeLens Sample Provider")
{
Priority = 600,
};
#pragma warning restore CEE0027 // String not localized

public Task<CodeLens?> TryCreateCodeLensAsync(CodeElement codeElement, CodeElementContext codeElementContext, CancellationToken token)
{
if (codeElement.Kind == MarkdownCodeLensTagger.SectionCodeElementKind)
{
return Task.FromResult<CodeLens?>(new MarkdownCodeLens(codeElement));
}

return Task.FromResult<CodeLens?>(null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if INPROC
namespace InProcFeatureGallery;
#else
namespace FeatureGallery;
#endif

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Extensibility.Editor;
using Microsoft.VisualStudio.Threading;

#pragma warning disable VSEXTPREVIEW_CODELENS // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
#pragma warning disable VSEXTPREVIEW_TAGGERS // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

internal class MarkdownCodeLensTagger : TextViewTagger<CodeLensTag>
{
public static readonly CodeElementKind SectionCodeElementKind = "Section";

private readonly MarkdownTaggerProvider provider;
private readonly Uri documentUri;
private readonly AsyncSemaphore semaphore = new(1);

private ITextDocumentSnapshot? currentDocumentSnapshot;
private bool needsUpdate;
private bool updateRunning;

public MarkdownCodeLensTagger(MarkdownTaggerProvider provider, Uri documentUri)
{
this.provider = provider;
this.documentUri = documentUri;
}

public override void Dispose()
{
this.provider.RemoveCodeLensTagger(this.documentUri, this);
this.semaphore.Dispose();
base.Dispose();
}

public async Task TextViewChangedAsync(ITextViewSnapshot textView, IReadOnlyList<TextEdit> edits, CancellationToken cancellationToken)
{
if (edits.Count == 0)
{
return;
}

var documentBefore = edits[0].Range.Document;
var documentAfter = textView.Document;

using var semaphoreReleaser = await this.semaphore.EnterAsync();

// Only queue a tags calculation if we haven't already queued it for a newer version of the document.
if (this.currentDocumentSnapshot is null || this.currentDocumentSnapshot.RpcContract.Version < documentAfter.RpcContract.Version)
{
// If we already have a request to update the tags, let's just update the current document snapshot so that tags are calculated
// with the latest version of the document.
if (this.needsUpdate)
{
this.currentDocumentSnapshot = documentAfter;
return;
}

// Only recalculate tags if a line starting with # was touched (added, removed, or modified).
if (Lines(
documentBefore,
edits.Select(e => e.Range))
.Any(l => l.StartsWith("#")) ||
Lines(
documentAfter,
edits.Select(e => e.Range.TranslateTo(documentAfter, TextRangeTrackingMode.EdgeInclusive)))
.Any(l => l.StartsWith("#")))
{
this.currentDocumentSnapshot = documentAfter;
_ = this.RunCreateTagsAsync();
}
}
}

protected override async Task RequestTagsAsync(NormalizedTextRangeCollection requestedRanges, bool recalculateAll, CancellationToken cancellationToken)
{
if (requestedRanges.Count == 0 || requestedRanges.TextDocumentSnapshot is null)
{
return;
}

using var semaphoreReleaser = await this.semaphore.EnterAsync();

// Only queue a tags calculation if we haven't already queued it for a newer version of the document. If we are asked to recalculate all, we always recalculate, but
// we use the latest between the current snapshot and the requested snapshot.
if (recalculateAll)
{
this.currentDocumentSnapshot =
this.currentDocumentSnapshot is not null && this.currentDocumentSnapshot.RpcContract.Version >= requestedRanges.TextDocumentSnapshot.RpcContract.Version ?
this.currentDocumentSnapshot :
requestedRanges.TextDocumentSnapshot;
_ = this.RunCreateTagsAsync();
}
else if (this.currentDocumentSnapshot is null || this.currentDocumentSnapshot.RpcContract.Version < requestedRanges.TextDocumentSnapshot.RpcContract.Version)
{
this.currentDocumentSnapshot = requestedRanges.TextDocumentSnapshot;
_ = this.RunCreateTagsAsync();
}
}

private static IEnumerable<TextRange> Lines(ITextDocumentSnapshot document, IEnumerable<TextRange> ranges)
=> ranges
.SelectMany(r =>
{
var startLine = r.Document.GetLineNumberFromPosition(r.Start);
var endLine = r.Document.GetLineNumberFromPosition(r.End);
return Enumerable.Range(startLine, endLine - startLine + 1);
})
.Distinct()
.Select(l => document.Lines[l].Text);

private async Task RunCreateTagsAsync()
{
// we are still under the semaphore here
this.needsUpdate = true;

// If we are already running the RunCreateTagsAsync loop, we don't need to start another one.
if (this.updateRunning)
{
return;
}

this.updateRunning = true;
while (true)
{
ITextDocumentSnapshot document;
{
// On the first iteration, since the caller owns the semaphore, this will always yield.
using var semaphoreReleaser = await this.semaphore.EnterAsync();
if (!this.needsUpdate || this.currentDocumentSnapshot is null)
{
this.updateRunning = false;
return;
}

this.needsUpdate = false;
document = this.currentDocumentSnapshot;
}

// We don't hold the semaphore while running CreateTagsAsync, that allows new requests to run tag calculation to happen.
await this.CreateTagsAsync(document);
}
}

private async Task CreateTagsAsync(ITextDocumentSnapshot document)
{
Dictionary<string, int> sections = new();

List<TaggedTrackingTextRange<CodeLensTag>> tags = new();
foreach (var line in document!.Lines)
{
int level = line.Text.TakeWhile(c => c == '#').Count();
if (level > 0 && level <= 6)
{
var description = line.Text.CopyToString().TrimStart('#').Trim();

var identifier = new string(description
.Where(c => char.IsLetterOrDigit(c) || c == ' ')
.Select(c => c == ' ' ? '-' : char.ToLowerInvariant(c))
.ToArray());

if (sections.TryGetValue(identifier, out var count))
{
sections[identifier] = count + 1;
identifier = $"{identifier}-{count}";
}
else
{
sections.Add(identifier, 1);
}

tags.Add(new(new(document, line.Text.Start, line.Text.Length, TextRangeTrackingMode.EdgeInclusive), new(SectionCodeElementKind)
{
UniqueIdentifier = identifier,
Description = $"Level {level} section: {description}",
DisplayBeforeCreatingCodeLenses = true,
Properties = new()
{
["Level"] = level.ToString(),
["Title"] = description,
},
}));
}
}

await this.UpdateTagsAsync([new(document, 0, document.Length)], tags, CancellationToken.None);
}
}
Loading
Loading