Repository navigation
Expand file tree
/
Copy pathextension.ts
More file actions
119 lines (108 loc) · 3.14 KB
/
Copy pathextension.ts
File metadata and controls
119 lines (108 loc) · 3.14 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* @file extension entry
* @author netcon
*/
import * as vscode from 'vscode';
import { SettingsView } from '@/views/settings-view';
import { setExtensionContext } from '@/helpers/context';
import {
commandUpdateToken,
commandValidateToken,
commandClearToken,
commandCheckoutRef,
commandGetCurrentAuthority,
commandOpenGitpod,
} from '@/commands';
import {
GitHub1sFileSystemProvider,
GitHub1sFileSearchProvider,
GitHub1sTextSearchProvider,
GitHub1sSubmoduleDecorationProvider,
} from '@/providers';
import { showSponsors } from '@/sponsors';
import { showGitpod } from '@/gitpod';
import router from '@/router';
import { activateSourceControl } from '@/source-control';
import { registerEventListeners } from '@/listeners';
import { PageType } from './router/types';
export async function activate(context: vscode.ExtensionContext) {
// set the global context for convenient
setExtensionContext(context);
// Ensure the router has been initialized at first
await router.initialize();
// register the necessary event listeners
registerEventListeners();
// providers
const fsProvider = new GitHub1sFileSystemProvider();
context.subscriptions.push(
vscode.workspace.registerFileSystemProvider(
GitHub1sFileSystemProvider.scheme,
fsProvider,
{
isCaseSensitive: true,
isReadonly: true,
}
),
vscode.workspace.registerFileSearchProvider(
GitHub1sFileSearchProvider.scheme,
new GitHub1sFileSearchProvider(fsProvider)
),
vscode.workspace.registerTextSearchProvider(
GitHub1sTextSearchProvider.scheme,
new GitHub1sTextSearchProvider()
),
vscode.window.registerFileDecorationProvider(
new GitHub1sSubmoduleDecorationProvider(fsProvider)
)
);
// views
context.subscriptions.push(
vscode.window.registerWebviewViewProvider(
SettingsView.viewType,
new SettingsView()
)
);
// commands
context.subscriptions.push(
// validate GitHub OAuth Token
vscode.commands.registerCommand(
'github1s.validate-token',
commandValidateToken
),
// update GitHub OAuth Token
vscode.commands.registerCommand(
'github1s.update-token',
commandUpdateToken
),
// clear GitHub OAuth Token
vscode.commands.registerCommand('github1s.clear-token', commandClearToken),
// get current authority (`${owner}+${repo}+${ref}`)
vscode.commands.registerCommand(
'github1s.get-current-authority',
commandGetCurrentAuthority
),
// checkout to other branch/tag/commit
vscode.commands.registerCommand(
'github1s.checkout-ref',
commandCheckoutRef
),
// open current repository on gitpod
vscode.commands.registerCommand('github1s.open-gitpod', commandOpenGitpod)
);
// activate SourceControl features,
activateSourceControl();
// sponsors in Status Bar
showSponsors();
await showGitpod();
// open corresponding editor if there is a filePath specified in browser url
const { filePath, pageType } = await router.getState();
if (filePath && [PageType.TREE, PageType.BLOB].includes(pageType)) {
vscode.commands.executeCommand(
pageType === PageType.TREE ? 'revealInExplorer' : 'vscode.open',
vscode.Uri.parse('').with({
scheme: GitHub1sFileSystemProvider.scheme,
path: filePath,
})
);
}
}