Skip to content

Commit 926a40c

Browse files
Add tests for Documentation Live Preview (#1285)
* add tests for Documentation Live Preview * enable all nightly runs when the `full-test-run` label is added to a PR * move context keys into WorkspaceContext so that they can be accessed outside of the extension --------- Co-authored-by: Michael (SPG) Weng <[email protected]>
1 parent 79188e8 commit 926a40c

File tree

18 files changed

+329
-67
lines changed

18 files changed

+329
-67
lines changed

.github/workflows/pull_request.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
with:
5050
needs_token: true
5151
# Linux
52-
linux_exclude_swift_versions: '[{"swift_version": "nightly-6.1"},{"swift_version": "nightly-6.2"},{"swift_version": "nightly-main"}]'
52+
linux_exclude_swift_versions: "${{ contains(github.event.pull_request.labels.*.name, 'full-test-run') && '[{\"swift_version\": \"nightly-6.1\"}]' || '[{\"swift_version\": \"nightly-6.1\"},{\"swift_version\": \"nightly-6.2\"},{\"swift_version\": \"nightly-main\"}]' }}"
5353
linux_env_vars: |
5454
NODE_VERSION=v20.19.0
5555
NODE_PATH=/usr/local/nvm/versions/node/v20.19.0/bin
@@ -61,7 +61,7 @@ jobs:
6161
linux_pre_build_command: . .github/workflows/scripts/setup-linux.sh
6262
linux_build_command: ./scripts/test.sh
6363
# Windows
64-
windows_exclude_swift_versions: '[{"swift_version": "nightly-6.1"},{"swift_version": "nightly-6.2"},{"swift_version": "nightly"}]'
64+
windows_exclude_swift_versions: "${{ contains(github.event.pull_request.labels.*.name, 'full-test-run') && '[{\"swift_version\": \"nightly-6.1\"},{\"swift_version\": \"nightly\"}]' || '[{\"swift_version\": \"nightly-6.1\"},{\"swift_version\": \"nightly-6.2\"},{\"swift_version\": \"nightly\"}]' }}"
6565
windows_env_vars: |
6666
CI=1
6767
FAST_TEST_RUN=${{ contains(github.event.pull_request.labels.*.name, 'full-test-run') && '0' || '1'}}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// swift-tools-version: 6.1
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "documentation-live-preview",
8+
products: [
9+
// Products define the executables and libraries a package produces, making them visible to other packages.
10+
.library(
11+
name: "Library",
12+
targets: ["Library"]),
13+
],
14+
targets: [
15+
// Targets are the basic building blocks of a package, defining a module or a test suite.
16+
// Targets can depend on other targets in this package and products from dependencies.
17+
.target(
18+
name: "Library"),
19+
]
20+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Getting Started
2+
3+
This is the getting started page.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@Tutorial(time: 30) {
2+
@Intro(title: "Library") {
3+
Library Tutorial
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@Tutorials(name: "SlothCreator") {
2+
@Intro(title: "Meet Library") {
3+
Library Tutorial Overview
4+
}
5+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// The Swift Programming Language
2+
// https://docs.swift.org/swift-book
3+
4+
/// The entry point for this arbitrary library.
5+
///
6+
/// Used for testing the Documentation Live Preview.
7+
public struct EntryPoint {
8+
/// The name of this EntryPoint
9+
public let name: String
10+
11+
/// Creates a new EntryPoint
12+
/// - Parameter name: the name of this entry point
13+
public init(name: String) {
14+
self.name = name
15+
}
16+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Used to test Live Preview with an unsupported file.

src/SwiftSnippets.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import * as vscode from "vscode";
1616
import * as path from "path";
17-
import contextKeys from "./contextKeys";
1817
import { createSwiftTask } from "./tasks/SwiftTaskProvider";
1918
import { WorkspaceContext } from "./WorkspaceContext";
2019
import { createSnippetConfiguration, debugLaunchConfig } from "./debugger/launch";
@@ -30,16 +29,16 @@ export function setSnippetContextKey(ctx: WorkspaceContext) {
3029
!ctx.currentDocument ||
3130
ctx.currentFolder.swiftVersion.isLessThan({ major: 5, minor: 7, patch: 0 })
3231
) {
33-
contextKeys.fileIsSnippet = false;
32+
ctx.contextKeys.fileIsSnippet = false;
3433
return;
3534
}
3635

3736
const filename = ctx.currentDocument.fsPath;
3837
const snippetsFolder = path.join(ctx.currentFolder.folder.fsPath, "Snippets");
3938
if (filename.startsWith(snippetsFolder)) {
40-
contextKeys.fileIsSnippet = true;
39+
ctx.contextKeys.fileIsSnippet = true;
4140
} else {
42-
contextKeys.fileIsSnippet = false;
41+
ctx.contextKeys.fileIsSnippet = false;
4342
}
4443
return;
4544
}

src/WorkspaceContext.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { LanguageClientToolchainCoordinator } from "./sourcekit-lsp/LanguageClie
2222
import { TaskManager } from "./tasks/TaskManager";
2323
import { makeDebugConfigurations } from "./debugger/launch";
2424
import configuration from "./configuration";
25-
import contextKeys from "./contextKeys";
25+
import { ContextKeys } from "./contextKeys";
2626
import { setSnippetContextKey } from "./SwiftSnippets";
2727
import { CommentCompletionProviders } from "./editor/CommentCompletion";
2828
import { SwiftBuildStatus } from "./ui/SwiftBuildStatus";
@@ -77,6 +77,7 @@ export class WorkspaceContext implements vscode.Disposable {
7777

7878
constructor(
7979
extensionContext: vscode.ExtensionContext,
80+
public contextKeys: ContextKeys,
8081
public logger: SwiftLogger,
8182
public globalToolchain: SwiftToolchain
8283
) {
@@ -233,9 +234,9 @@ export class WorkspaceContext implements vscode.Disposable {
233234
*/
234235
updateContextKeys(folderContext: FolderContext | null) {
235236
if (!folderContext) {
236-
contextKeys.hasPackage = false;
237-
contextKeys.hasExecutableProduct = false;
238-
contextKeys.packageHasDependencies = false;
237+
this.contextKeys.hasPackage = false;
238+
this.contextKeys.hasExecutableProduct = false;
239+
this.contextKeys.packageHasDependencies = false;
239240
return;
240241
}
241242

@@ -244,9 +245,9 @@ export class WorkspaceContext implements vscode.Disposable {
244245
folderContext.swiftPackage.executableProducts,
245246
folderContext.swiftPackage.dependencies,
246247
]).then(([foundPackage, executableProducts, dependencies]) => {
247-
contextKeys.hasPackage = foundPackage;
248-
contextKeys.hasExecutableProduct = executableProducts.length > 0;
249-
contextKeys.packageHasDependencies = dependencies.length > 0;
248+
this.contextKeys.hasPackage = foundPackage;
249+
this.contextKeys.hasExecutableProduct = executableProducts.length > 0;
250+
this.contextKeys.packageHasDependencies = dependencies.length > 0;
250251
});
251252
}
252253

@@ -258,23 +259,23 @@ export class WorkspaceContext implements vscode.Disposable {
258259
const target = await this.currentFolder?.swiftPackage.getTarget(
259260
this.currentDocument?.fsPath
260261
);
261-
contextKeys.currentTargetType = target?.type;
262+
this.contextKeys.currentTargetType = target?.type;
262263
} else {
263-
contextKeys.currentTargetType = undefined;
264+
this.contextKeys.currentTargetType = undefined;
264265
}
265266

266267
if (this.currentFolder) {
267268
const languageClient = this.languageClientManager.get(this.currentFolder);
268269
await languageClient.useLanguageClient(async client => {
269270
const experimentalCaps = client.initializeResult?.capabilities.experimental;
270271
if (!experimentalCaps) {
271-
contextKeys.supportsReindexing = false;
272-
contextKeys.supportsDocumentationLivePreview = false;
272+
this.contextKeys.supportsReindexing = false;
273+
this.contextKeys.supportsDocumentationLivePreview = false;
273274
return;
274275
}
275-
contextKeys.supportsReindexing =
276+
this.contextKeys.supportsReindexing =
276277
experimentalCaps[ReIndexProjectRequest.method] !== undefined;
277-
contextKeys.supportsDocumentationLivePreview =
278+
this.contextKeys.supportsDocumentationLivePreview =
278279
experimentalCaps[DocCDocumentationRequest.method] !== undefined;
279280
});
280281
}
@@ -293,7 +294,7 @@ export class WorkspaceContext implements vscode.Disposable {
293294
break;
294295
}
295296
}
296-
contextKeys.packageHasPlugins = hasPlugins;
297+
this.contextKeys.packageHasPlugins = hasPlugins;
297298
}
298299

299300
/** Setup the vscode event listeners to catch folder changes and active window changes */

src/commands/dependencies/updateDepViewList.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
import contextKeys from "../../contextKeys";
1615
import { FolderOperation, WorkspaceContext } from "../../WorkspaceContext";
1716

1817
export function updateDependenciesViewList(ctx: WorkspaceContext, flatList: boolean) {
1918
if (ctx.currentFolder) {
20-
contextKeys.flatDependenciesList = flatList;
19+
ctx.contextKeys.flatDependenciesList = flatList;
2120
void ctx.fireEvent(ctx.currentFolder, FolderOperation.packageViewUpdated);
2221
}
2322
}

0 commit comments

Comments
 (0)