Skip to content

Commit 6832054

Browse files
authored
Add command that enables testing of release notes editor (microsoft#205556)
Also fix double setting name
1 parent c5327e5 commit 6832054

File tree

6 files changed

+41
-10
lines changed

6 files changed

+41
-10
lines changed

src/vs/workbench/contrib/markdown/browser/markdownSettingRenderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export class SimpleSettingRenderer {
169169
return `<code tabindex="0"><a href="${href}" class="codesetting" title="${title}" aria-role="button"><svg width="14" height="14" viewBox="0 0 15 15" xmlns="http://www.w3.org/2000/svg" fill="currentColor"><path d="M9.1 4.4L8.6 2H7.4l-.5 2.4-.7.3-2-1.3-.9.8 1.3 2-.2.7-2.4.5v1.2l2.4.5.3.8-1.3 2 .8.8 2-1.3.8.3.4 2.3h1.2l.5-2.4.8-.3 2 1.3.8-.8-1.3-2 .3-.8 2.3-.4V7.4l-2.4-.5-.3-.8 1.3-2-.8-.8-2 1.3-.7-.2zM9.4 1l.5 2.4L12 2.1l2 2-1.4 2.1 2.4.4v2.8l-2.4.5L14 12l-2 2-2.1-1.4-.5 2.4H6.6l-.5-2.4L4 13.9l-2-2 1.4-2.1L1 9.4V6.6l2.4-.5L2.1 4l2-2 2.1 1.4.4-2.4h2.8zm.6 7c0 1.1-.9 2-2 2s-2-.9-2-2 .9-2 2-2 2 .9 2 2zM8 9c.6 0 1-.4 1-1s-.4-1-1-1-1 .4-1 1 .4 1 1 1z"/></svg>
170170
<span class="separator"></span>
171171
<span class="setting-name">${setting.key}</span>
172-
</a>`;
172+
</a></code><code>`;
173173
}
174174

175175
private renderFeature(setting: ISetting, newValue: string): string | undefined {

src/vs/workbench/contrib/markdown/test/browser/markdownSettingRenderer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ suite('Markdown Setting Renderer Test', () => {
7676
`<code tabindex="0"><a href="code-setting://example.booleanSetting" class="codesetting" title="Try feature" aria-role="button"><svg width="14" height="14" viewBox="0 0 15 15" xmlns="http://www.w3.org/2000/svg" fill="currentColor"><path d="M9.1 4.4L8.6 2H7.4l-.5 2.4-.7.3-2-1.3-.9.8 1.3 2-.2.7-2.4.5v1.2l2.4.5.3.8-1.3 2 .8.8 2-1.3.8.3.4 2.3h1.2l.5-2.4.8-.3 2 1.3.8-.8-1.3-2 .3-.8 2.3-.4V7.4l-2.4-.5-.3-.8 1.3-2-.8-.8-2 1.3-.7-.2zM9.4 1l.5 2.4L12 2.1l2 2-1.4 2.1 2.4.4v2.8l-2.4.5L14 12l-2 2-2.1-1.4-.5 2.4H6.6l-.5-2.4L4 13.9l-2-2 1.4-2.1L1 9.4V6.6l2.4-.5L2.1 4l2-2 2.1 1.4.4-2.4h2.8zm.6 7c0 1.1-.9 2-2 2s-2-.9-2-2 .9-2 2-2 2 .9 2 2zM8 9c.6 0 1-.4 1-1s-.4-1-1-1-1 .4-1 1 .4 1 1 1z"/></svg>
7777
<span class="separator"></span>
7878
<span class="setting-name">example.booleanSetting</span>
79-
</a>`);
79+
</a></code><code>`);
8080
});
8181

8282
test('actions with no value', () => {

src/vs/workbench/contrib/update/browser/releaseNotesEditor.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { DisposableStore } from 'vs/base/common/lifecycle';
3333
import { SimpleSettingRenderer } from 'vs/workbench/contrib/markdown/browser/markdownSettingRenderer';
3434
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
3535
import { Schemas } from 'vs/base/common/network';
36+
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
3637

3738
export class ReleaseNotesManager {
3839
private readonly _simpleSettingRenderer: SimpleSettingRenderer;
@@ -44,6 +45,7 @@ export class ReleaseNotesManager {
4445
private readonly disposables = new DisposableStore();
4546

4647
public constructor(
48+
private readonly _useCurrentFile: boolean,
4749
@IEnvironmentService private readonly _environmentService: IEnvironmentService,
4850
@IKeybindingService private readonly _keybindingService: IKeybindingService,
4951
@ILanguageService private readonly _languageService: ILanguageService,
@@ -52,6 +54,7 @@ export class ReleaseNotesManager {
5254
@IConfigurationService private readonly _configurationService: IConfigurationService,
5355
@IEditorService private readonly _editorService: IEditorService,
5456
@IEditorGroupsService private readonly _editorGroupService: IEditorGroupsService,
57+
@ICodeEditorService private readonly _codeEditorService: ICodeEditorService,
5558
@IWebviewWorkbenchService private readonly _webviewWorkbenchService: IWebviewWorkbenchService,
5659
@IExtensionService private readonly _extensionService: IExtensionService,
5760
@IProductService private readonly _productService: IProductService,
@@ -196,7 +199,7 @@ export class ReleaseNotesManager {
196199
const fetchReleaseNotes = async () => {
197200
let text;
198201
try {
199-
text = await asTextOrError(await this._requestService.request({ url }, CancellationToken.None));
202+
text = this._useCurrentFile ? this._codeEditorService.getActiveCodeEditor()?.getModel()?.getValue() : await asTextOrError(await this._requestService.request({ url }, CancellationToken.None));
200203
} catch {
201204
throw new Error('Failed to fetch release notes');
202205
}
@@ -517,4 +520,3 @@ export class ReleaseNotesManager {
517520
}
518521
}
519522
}
520-

src/vs/workbench/contrib/update/browser/update.contribution.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiati
1717
import { isWindows } from 'vs/base/common/platform';
1818
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
1919
import { mnemonicButtonLabel } from 'vs/base/common/labels';
20-
import { ShowCurrentReleaseNotesActionId } from 'vs/workbench/contrib/update/common/update';
20+
import { ShowCurrentReleaseNotesActionId, ShowCurrentReleaseNotesFromCurrentFileActionId } from 'vs/workbench/contrib/update/common/update';
2121
import { IsWebContext } from 'vs/platform/contextkey/common/contextkeys';
2222
import { IOpenerService } from 'vs/platform/opener/common/opener';
2323
import { IProductService } from 'vs/platform/product/common/productService';
@@ -59,7 +59,7 @@ export class ShowCurrentReleaseNotesAction extends Action2 {
5959
const openerService = accessor.get(IOpenerService);
6060

6161
try {
62-
await showReleaseNotesInEditor(instantiationService, productService.version);
62+
await showReleaseNotesInEditor(instantiationService, productService.version, false);
6363
} catch (err) {
6464
if (productService.releaseNotesUrl) {
6565
await openerService.open(URI.parse(productService.releaseNotesUrl));
@@ -70,7 +70,35 @@ export class ShowCurrentReleaseNotesAction extends Action2 {
7070
}
7171
}
7272

73+
export class ShowCurrentReleaseNotesFromCurrentFileAction extends Action2 {
74+
75+
constructor() {
76+
super({
77+
id: ShowCurrentReleaseNotesFromCurrentFileActionId,
78+
title: {
79+
...localize2('showReleaseNotesCurrentFile', "Open Current File as Release Notes"),
80+
mnemonicTitle: localize({ key: 'mshowReleaseNotes', comment: ['&& denotes a mnemonic'] }, "Show &&Release Notes"),
81+
},
82+
category: localize2('developerCategory', "Developer"),
83+
f1: true,
84+
precondition: RELEASE_NOTES_URL
85+
});
86+
}
87+
88+
async run(accessor: ServicesAccessor): Promise<void> {
89+
const instantiationService = accessor.get(IInstantiationService);
90+
const productService = accessor.get(IProductService);
91+
92+
try {
93+
await showReleaseNotesInEditor(instantiationService, productService.version, true);
94+
} catch (err) {
95+
throw new Error(localize('releaseNotesFromFileNone', "Cannot open the current file as Release Notes"));
96+
}
97+
}
98+
}
99+
73100
registerAction2(ShowCurrentReleaseNotesAction);
101+
registerAction2(ShowCurrentReleaseNotesFromCurrentFileAction);
74102

75103
// Update
76104

src/vs/workbench/contrib/update/browser/update.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ export const DOWNLOAD_URL = new RawContextKey<string>('downloadUrl', '');
3838

3939
let releaseNotesManager: ReleaseNotesManager | undefined = undefined;
4040

41-
export function showReleaseNotesInEditor(instantiationService: IInstantiationService, version: string) {
41+
export function showReleaseNotesInEditor(instantiationService: IInstantiationService, version: string, useCurrentFile: boolean) {
4242
if (!releaseNotesManager) {
43-
releaseNotesManager = instantiationService.createInstance(ReleaseNotesManager);
43+
releaseNotesManager = instantiationService.createInstance(ReleaseNotesManager, useCurrentFile);
4444
}
4545

4646
return releaseNotesManager.show(version);
@@ -61,7 +61,7 @@ async function openLatestReleaseNotesInBrowser(accessor: ServicesAccessor) {
6161
async function showReleaseNotes(accessor: ServicesAccessor, version: string) {
6262
const instantiationService = accessor.get(IInstantiationService);
6363
try {
64-
await showReleaseNotesInEditor(instantiationService, version);
64+
await showReleaseNotesInEditor(instantiationService, version, false);
6565
} catch (err) {
6666
try {
6767
await instantiationService.invokeFunction(openLatestReleaseNotesInBrowser);
@@ -135,7 +135,7 @@ export class ProductContribution implements IWorkbenchContribution {
135135

136136
// was there a major/minor update? if so, open release notes
137137
if (shouldShowReleaseNotes && !environmentService.skipReleaseNotes && releaseNotesUrl && lastVersion && currentVersion && isMajorMinorUpdate(lastVersion, currentVersion)) {
138-
showReleaseNotesInEditor(instantiationService, productService.version)
138+
showReleaseNotesInEditor(instantiationService, productService.version, false)
139139
.then(undefined, () => {
140140
notificationService.prompt(
141141
severity.Info,

src/vs/workbench/contrib/update/common/update.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
export const ShowCurrentReleaseNotesActionId = 'update.showCurrentReleaseNotes';
7+
export const ShowCurrentReleaseNotesFromCurrentFileActionId = 'developer.showCurrentFileAsReleaseNotes';

0 commit comments

Comments
 (0)