-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathBuiltinExtensionWorkspacePlugin.swift
More file actions
72 lines (62 loc) · 2.3 KB
/
BuiltinExtensionWorkspacePlugin.swift
File metadata and controls
72 lines (62 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import Foundation
import Workspace
public final class BuiltinExtensionWorkspacePlugin: WorkspacePlugin {
let extensionManager: BuiltinExtensionManager
public init(workspace: Workspace, extensionManager: BuiltinExtensionManager = .shared) {
self.extensionManager = extensionManager
super.init(workspace: workspace)
}
override public func didOpenFilespace(_ filespace: Filespace) {
notifyOpenFile(filespace: filespace)
}
override public func didSaveFilespace(_ filespace: Filespace) {
notifySaveFile(filespace: filespace)
}
override public func didUpdateFilespace(_ filespace: Filespace, content: String) {
notifyUpdateFile(filespace: filespace, content: content)
}
override public func didCloseFilespace(_ fileURL: URL) {
Task {
for ext in extensionManager.extensions {
ext.workspace(
.init(workspaceURL: workspaceURL, projectURL: projectRootURL),
didCloseDocumentAt: fileURL
)
}
}
}
public func notifyOpenFile(filespace: Filespace) {
Task {
guard filespace.isTextReadable else { return }
for ext in extensionManager.extensions {
ext.workspace(
.init(workspaceURL: workspaceURL, projectURL: projectRootURL),
didOpenDocumentAt: filespace.fileURL
)
}
}
}
public func notifyUpdateFile(filespace: Filespace, content: String) {
Task {
guard filespace.isTextReadable else { return }
for ext in extensionManager.extensions {
ext.workspace(
.init(workspaceURL: workspaceURL, projectURL: projectRootURL),
didUpdateDocumentAt: filespace.fileURL,
content: content
)
}
}
}
public func notifySaveFile(filespace: Filespace) {
Task {
guard filespace.isTextReadable else { return }
for ext in extensionManager.extensions {
ext.workspace(
.init(workspaceURL: workspaceURL, projectURL: projectRootURL),
didSaveDocumentAt: filespace.fileURL
)
}
}
}
}