Repository navigation
Expand file tree
/
Copy pathconfig.ts
More file actions
148 lines (132 loc) · 4.42 KB
/
Copy pathconfig.ts
File metadata and controls
148 lines (132 loc) · 4.42 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* @file config for different platform
* @author netcon
*/
import githubLogoUrl from './assets/github.svg';
import gitlabLogoUrl from './assets/gitlab.svg';
import bitbucketLogoUrl from './assets/bitbucket.svg';
import npmLogoUrl from './assets/npm.svg';
const createFolderWorkspace = (scheme: string) => ({
folderUri: { scheme, authority: '', path: '/', query: '', fragment: '' },
});
const openGitHub1sPage = () => {
return window.open('https://github.com/conwnet/github1s', '_blank');
};
const openOfficialPage = (origin: string) => {
const targetPath = window.location.pathname + window.location.search + window.location.hash;
return window.open(origin + targetPath, '_blank');
};
const createWindowIndicator = (label: string) => ({
tooltip: label || '',
label: label || '$(remote)',
command: 'github1s.commands.openRepository',
});
const createConfigurationDefaults = (disableSomeAnyCodeFeatures: boolean) => {
const configurationDefaults = {
'workbench.colorTheme': 'Default Dark+',
'telemetry.telemetryLevel': 'off',
'workbench.startupEditor': 'readme',
'workbench.editorAssociations': { '*.md': 'vscode.markdown.preview.editor' },
'markdown.preview.doubleClickToSwitchToEditor': false,
'chat.disableAIFeatures': true,
} as Record<string, any>;
// disable some anycode features when we can use sourcegraph instead
if (disableSomeAnyCodeFeatures) {
configurationDefaults['anycode.language.features'] = {
completions: false,
definitions: false,
references: false,
highlights: true,
outline: true,
workspaceSymbols: true,
folding: false,
diagnostics: false,
};
}
return configurationDefaults;
};
export enum Platform {
GitHub = 'GitHub',
GitLab = 'GitLab',
Bitbucket = 'Bitbucket',
npm = 'npm',
}
export const createVSCodeWebConfig = (platform: Platform, repository: string): any => {
if (platform === Platform.GitLab) {
return {
hideTextFileLabelDecorations: !!repository,
workspace: repository ? createFolderWorkspace('gitlab1s') : undefined,
workspaceId: repository ? 'gitlab1s:' + repository : '',
workspaceLabel: repository,
logo: {
title: 'Open on GitLab',
icon: gitlabLogoUrl,
onClick: () => (repository ? openOfficialPage(GITLAB_ORIGIN) : openGitHub1sPage()),
},
};
}
// bitbucket is not available now
if (platform === Platform.Bitbucket) {
return {
hideTextFileLabelDecorations: !!repository,
workspace: repository ? createFolderWorkspace('bitbucket1s') : undefined,
workspaceId: repository ? 'bitbucket1s:' + repository : '',
workspaceLabel: repository,
logo: {
title: 'Open on Bitbucket',
icon: bitbucketLogoUrl,
onClick: () => (repository ? openOfficialPage('https://bitbucket.org') : openGitHub1sPage()),
},
};
}
if (platform === Platform.npm) {
return {
hideTextFileLabelDecorations: !!repository,
workspace: repository ? createFolderWorkspace('npmjs1s') : undefined,
workspaceId: repository ? 'npmjs1s:' + repository : '',
workspaceLabel: repository,
logo: {
title: 'Open on npm',
icon: npmLogoUrl,
onClick: () => (repository ? openOfficialPage('https://npmjs.com') : openGitHub1sPage()),
},
};
}
const isOnlineEditor = repository === 'editor';
return {
hideTextFileLabelDecorations: !isOnlineEditor,
workspace: !isOnlineEditor ? createFolderWorkspace(repository ? 'github1s' : 'discovery') : undefined,
workspaceId: !isOnlineEditor ? 'github1s:' + (repository || 'discovery') : '',
workspaceLabel: repository || (isOnlineEditor ? '' : 'GitHub Discovery'),
logo: {
title: 'Open on GitHub',
icon: githubLogoUrl,
onClick: () => (repository ? openOfficialPage(GITHUB_ORIGIN) : openGitHub1sPage()),
},
};
};
export const createWorkbenchOptions = (platform: Platform, repository: string): any => {
if (platform === Platform.GitLab) {
return {
windowIndicator: createWindowIndicator(repository),
configurationDefaults: createConfigurationDefaults(!!repository),
};
}
// bitbucket is not available now
if (platform === Platform.Bitbucket) {
return {
windowIndicator: createWindowIndicator(repository),
configurationDefaults: createConfigurationDefaults(!!repository),
};
}
if (platform === Platform.npm) {
return {
windowIndicator: createWindowIndicator(repository),
configurationDefaults: createConfigurationDefaults(false),
};
}
return {
windowIndicator: createWindowIndicator(repository),
configurationDefaults: createConfigurationDefaults(!!repository),
};
};