Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
myhjmzy
code-server
提交
8a0f1d84
C
code-server
项目概览
myhjmzy
/
code-server
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
code-server
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
8a0f1d84
编写于
2月 06, 2020
作者:
A
Asher
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move start path logic out of patch and fix it
上级
efaeb3b1
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
107 addition
and
89 deletion
+107
-89
scripts/vscode.patch
scripts/vscode.patch
+18
-60
src/node/cli.ts
src/node/cli.ts
+27
-0
src/node/entry.ts
src/node/entry.ts
+7
-19
src/node/vscode/error.html
src/node/vscode/error.html
+1
-1
src/node/vscode/server.ts
src/node/vscode/server.ts
+54
-9
未找到文件。
scripts/vscode.patch
浏览文件 @
8a0f1d84
...
...
@@ -852,7 +852,7 @@ index 0000000000..eb62b87798
+}
diff --git a/src/vs/server/entry.ts b/src/vs/server/entry.ts
new file mode 100644
index 0000000000..
cb606e6a68
index 0000000000..
9995e9f7fc
--- /dev/null
+++ b/src/vs/server/entry.ts
@@ -0,0 +1,67 @@
...
...
@@ -897,8 +897,8 @@ index 0000000000..cb606e6a68
+ process.send(message);
+};
+
+// Wait for the init message then start up VS Code.
Future messages will return
+// new workbench options without starting a new instance.
+// Wait for the init message then start up VS Code.
Subsequent messages will
+//
return
new workbench options without starting a new instance.
+process.on('message', async (message: CodeServerMessage, socket) => {
+ logger.debug('got message from code-server', field('message', message));
+ switch (message.type) {
...
...
@@ -934,10 +934,10 @@ index 0000000000..56331ff1fc
+require('../../bootstrap-amd').load('vs/server/entry');
diff --git a/src/vs/server/ipc.d.ts b/src/vs/server/ipc.d.ts
new file mode 100644
index 0000000000..
218faa34d2
index 0000000000..
3bfef75d81
--- /dev/null
+++ b/src/vs/server/ipc.d.ts
@@ -0,0 +1,9
3
@@
@@ -0,0 +1,9
1
@@
+/**
+ * External interfaces for integration into code-server over IPC. No vs imports
+ * should be made in this file.
...
...
@@ -971,19 +971,18 @@ index 0000000000..218faa34d2
+export type VscodeMessage = ReadyMessage | OptionsMessage;
+
+export interface StartPath {
+
path?: string[] |
string;
+ workspace
?
: boolean;
+
url:
string;
+ workspace: boolean;
+}
+
+export interface
Settin
gs {
+
lastVisited?: StartPath
;
+export interface
Ar
gs {
+
_: string[]
;
+}
+
+export interface VscodeOptions {
+ readonly remoteAuthority: string;
+ readonly query: Query;
+ readonly args?: string[];
+ readonly settings: Settings;
+ readonly args: Args;
+ readonly startPath?: StartPath;
+}
+
+export interface VscodeOptionsMessage extends VscodeOptions {
...
...
@@ -1008,7 +1007,6 @@ index 0000000000..218faa34d2
+}
+
+export interface WorkbenchOptions {
+ readonly startPath?: StartPath;
+ readonly workbenchWebConfiguration: {
+ readonly remoteAuthority?: string;
+ readonly folderUri?: UriComponents;
...
...
@@ -2181,15 +2179,13 @@ index 0000000000..3c74512192
+}
diff --git a/src/vs/server/node/server.ts b/src/vs/server/node/server.ts
new file mode 100644
index 0000000000..
5207c90081
index 0000000000..
81d275a80a
--- /dev/null
+++ b/src/vs/server/node/server.ts
@@ -0,0 +1,293 @@
+import * as fs from 'fs-extra';
@@ -0,0 +1,253 @@
+import * as net from 'net';
+import * as path from 'path';
+import { Emitter } from 'vs/base/common/event';
+import { sanitizeFilePath } from 'vs/base/common/extpath';
+import { Schemas } from 'vs/base/common/network';
+import { URI } from 'vs/base/common/uri';
+import { getMachineId } from 'vs/base/node/id';
...
...
@@ -2232,12 +2228,10 @@ index 0000000000..5207c90081
+import { resolveCommonProperties } from 'vs/platform/telemetry/node/commonProperties';
+import { INodeProxyService, NodeProxyChannel } from 'vs/server/common/nodeProxy';
+import { TelemetryChannel } from 'vs/server/common/telemetry';
+import { Query,
StartPath,
VscodeOptions, WorkbenchOptions } from 'vs/server/ipc';
+import { Query, VscodeOptions, WorkbenchOptions } from 'vs/server/ipc';
+import { ExtensionEnvironmentChannel, FileProviderChannel, NodeProxyService } from 'vs/server/node/channel';
+import { parseArgs } from 'vs/server/node/cli';
+import { Connection, ExtensionHostConnection, ManagementConnection } from 'vs/server/node/connection';
+import { TelemetryClient } from 'vs/server/node/insights';
+import { logger } from 'vs/server/node/logger';
+import { getLocaleFromConfig, getNlsConfiguration } from 'vs/server/node/nls';
+import { Protocol } from 'vs/server/node/protocol';
+import { getUriTransformer } from 'vs/server/node/util';
...
...
@@ -2253,27 +2247,19 @@ index 0000000000..5207c90081
+
+ private readonly services = new ServiceCollection();
+ private servicesPromise?: Promise<void>;
+ private args?: ParsedArgs;
+
+ public async initialize(options: VscodeOptions): Promise<WorkbenchOptions> {
+ if (!this.args) {
+ this.args = parseArgs(options.args || []);
+ }
+ const transformer = getUriTransformer(options.remoteAuthority);
+ const startPath = await this.getFirstValidPath([
+ options.settings.lastVisited,
+ { path: this.args._[0] },
+ ]);
+ if (!this.servicesPromise) {
+ this.servicesPromise = this.initializeServices(
thi
s.args);
+ this.servicesPromise = this.initializeServices(
option
s.args);
+ }
+ await this.servicesPromise;
+ const environment = this.services.get(IEnvironmentService) as IEnvironmentService;
+ const startPath = options.startPath;
+ return {
+ startPath,
+ workbenchWebConfiguration: {
+ workspaceUri: startPath && startPath.workspace ?
transformer.transformOutgoing(URI.file(startPath.path)
) : undefined,
+ folderUri: startPath && !startPath.workspace ?
transformer.transformOutgoing(URI.file(startPath.path)
) : undefined,
+ workspaceUri: startPath && startPath.workspace ?
URI.parse(startPath.url
) : undefined,
+ folderUri: startPath && !startPath.workspace ?
URI.parse(startPath.url
) : undefined,
+ remoteAuthority: options.remoteAuthority,
+ logLevel: getLogLevel(environment),
+ },
...
...
@@ -2305,34 +2291,6 @@ index 0000000000..5207c90081
+ return true;
+ }
+
+ /**
+ * Choose the first valid path. If `workspace` is undefined then either a
+ * workspace or a directory are acceptable. Otherwise it must be a file if a
+ * workspace or a directory otherwise.
+ */
+ private async getFirstValidPath(startPaths: Array<StartPath | undefined>): Promise<{ path: string, workspace?: boolean} | undefined> {
+ const cwd = process.env.VSCODE_CWD || process.cwd();
+ for (let i = 0; i < startPaths.length; ++i) {
+ const startPath = startPaths[i];
+ if (!startPath) {
+ continue;
+ }
+ const paths = typeof startPath.path === 'string' ? [startPath.path] : (startPath.path || []);
+ for (let j = 0; j < paths.length; ++j) {
+ const p = sanitizeFilePath(paths[j], cwd);
+ try {
+ const stat = await fs.stat(p);
+ if (typeof startPath.workspace === 'undefined' || startPath.workspace !== stat.isDirectory()) {
+ return { path: p, workspace: !stat.isDirectory() };
+ }
+ } catch (error) {
+ logger.warn(error.message);
+ }
+ }
+ }
+ return undefined;
+ }
+
+ private async connect(message: ConnectionTypeRequest, protocol: Protocol): Promise<void> {
+ if (product.commit && message.commit !== product.commit) {
+ throw new Error(`Version mismatch (${message.commit} instead of ${product.commit})`);
...
...
src/node/cli.ts
0 → 100644
浏览文件 @
8a0f1d84
import
{
AuthType
}
from
"
./http
"
import
{
Args
as
VsArgs
}
from
"
../../lib/vscode/src/vs/server/ipc
"
export
interface
Args
extends
VsArgs
{
auth
?:
AuthType
"
base-path
"
?:
string
cert
?:
string
"
cert-key
"
?:
string
format
?:
string
host
?:
string
json
?:
boolean
open
?:
boolean
port
?:
string
socket
?:
string
version
?:
boolean
_
:
string
[]
}
// TODO: Implement proper CLI parser.
export
const
parse
=
():
Args
=>
{
const
last
=
process
.
argv
[
process
.
argv
.
length
-
1
]
return
{
version
:
process
.
argv
.
includes
(
"
--version
"
),
json
:
process
.
argv
.
includes
(
"
--json
"
),
_
:
last
&&
!
last
.
startsWith
(
"
-
"
)
?
[
last
]
:
[],
}
}
src/node/entry.ts
浏览文件 @
8a0f1d84
import
{
logger
}
from
"
@coder/logger
"
import
{
ApiHttpProvider
}
from
"
./api/server
"
import
{
MainHttpProvider
}
from
"
./app/server
"
import
{
Args
,
parse
}
from
"
./cli
"
import
{
AuthType
,
HttpServer
}
from
"
./http
"
import
{
generateCertificate
,
generatePassword
,
hash
,
open
}
from
"
./util
"
import
{
VscodeHttpProvider
}
from
"
./vscode/server
"
import
{
ipcMain
,
wrap
}
from
"
./wrapper
"
export
interface
Args
{
auth
?:
AuthType
"
base-path
"
?:
string
cert
?:
string
"
cert-key
"
?:
string
format
?:
string
host
?:
string
open
?:
boolean
port
?:
string
socket
?:
string
_
?:
string
[]
}
const
main
=
async
(
args
:
Args
=
{}):
Promise
<
void
>
=>
{
const
main
=
async
(
args
:
Args
):
Promise
<
void
>
=>
{
const
auth
=
args
.
auth
||
AuthType
.
Password
const
originalPassword
=
auth
===
AuthType
.
Password
&&
(
process
.
env
.
PASSWORD
||
(
await
generatePassword
()))
...
...
@@ -51,7 +39,7 @@ const main = async (args: Args = {}): Promise<void> => {
const
httpServer
=
new
HttpServer
(
options
)
httpServer
.
registerHttpProvider
(
"
/
"
,
MainHttpProvider
)
httpServer
.
registerHttpProvider
(
"
/api
"
,
ApiHttpProvider
,
httpServer
)
httpServer
.
registerHttpProvider
(
"
/vscode-embed
"
,
VscodeHttpProvider
,
[]
)
httpServer
.
registerHttpProvider
(
"
/vscode-embed
"
,
VscodeHttpProvider
,
args
)
ipcMain
().
onDispose
(()
=>
httpServer
.
dispose
())
...
...
@@ -88,10 +76,10 @@ const main = async (args: Args = {}): Promise<void> => {
}
}
// TODO: Implement CLI parser.
if
(
process
.
argv
.
includes
(
"
--version
"
)
)
{
const
args
=
parse
()
if
(
args
.
version
)
{
const
version
=
require
(
"
../../package.json
"
).
version
if
(
process
.
argv
.
includes
(
"
--json
"
)
)
{
if
(
args
.
json
)
{
console
.
log
({
codeServer
:
version
,
vscode
:
require
(
"
../../lib/vscode/package.json
"
).
version
,
...
...
@@ -101,5 +89,5 @@ if (process.argv.includes("--version")) {
}
process
.
exit
(
0
)
}
else
{
wrap
(
main
)
wrap
(
()
=>
main
(
args
)
)
}
src/node/vscode/error.html
浏览文件 @
8a0f1d84
...
...
@@ -6,7 +6,7 @@
<meta
http-equiv=
"Content-Security-Policy"
content=
"font-src 'self' fonts.gstatic.com; connect-src 'self'; default-src ws: wss: 'self'; style-src 'self' 'unsafe-inline' fonts.googleapis.com; script-src 'self' 'unsafe-inline'; manifest-src 'self'; img-src 'self' data:;"
>
<title>
code-server
</title>
</head>
<body>
<body
style=
"background-color:#272727;"
>
<div
id=
"root"
style=
"color:#f4f4f4;padding:20px;max-width:700px;"
>
{{ERROR}}
</div>
...
...
src/node/vscode/server.ts
浏览文件 @
8a0f1d84
import
{
field
,
logger
}
from
"
@coder/logger
"
import
*
as
cp
from
"
child_process
"
import
*
as
crypto
from
"
crypto
"
import
*
as
fs
from
"
fs-extra
"
import
*
as
http
from
"
http
"
import
*
as
net
from
"
net
"
import
*
as
path
from
"
path
"
import
*
as
url
from
"
url
"
import
{
CodeServerMessage
,
S
ettings
,
S
tartPath
,
VscodeMessage
,
VscodeOptions
,
WorkbenchOptions
,
}
from
"
../../../lib/vscode/src/vs/server/ipc
"
import
{
HttpCode
,
HttpError
}
from
"
../../common/http
"
import
{
generateUuid
}
from
"
../../common/util
"
import
{
Args
}
from
"
../cli
"
import
{
HttpProvider
,
HttpProviderOptions
,
HttpResponse
,
Route
}
from
"
../http
"
import
{
SettingsProvider
}
from
"
../settings
"
import
{
xdgLocalDir
}
from
"
../util
"
export
interface
Settings
{
lastVisited
:
StartPath
}
export
class
VscodeHttpProvider
extends
HttpProvider
{
private
readonly
serverRootPath
:
string
private
readonly
vsRootPath
:
string
...
...
@@ -24,7 +31,7 @@ export class VscodeHttpProvider extends HttpProvider {
private
_vscode
?:
Promise
<
cp
.
ChildProcess
>
private
workbenchOptions
?:
WorkbenchOptions
public
constructor
(
options
:
HttpProviderOptions
,
private
readonly
args
:
string
[]
)
{
public
constructor
(
options
:
HttpProviderOptions
,
private
readonly
args
:
Args
)
{
super
(
options
)
this
.
vsRootPath
=
path
.
resolve
(
this
.
rootPath
,
"
lib/vscode
"
)
this
.
serverRootPath
=
path
.
join
(
this
.
vsRootPath
,
"
out/vs/server
"
)
...
...
@@ -161,24 +168,26 @@ export class VscodeHttpProvider extends HttpProvider {
private
async
getRoot
(
request
:
http
.
IncomingMessage
,
route
:
Route
):
Promise
<
HttpResponse
>
{
const
settings
=
await
this
.
settings
.
read
()
const
startPath
=
await
this
.
getFirstValidPath
([
{
url
:
route
.
query
.
workspace
,
workspace
:
true
},
{
url
:
route
.
query
.
folder
,
workspace
:
false
},
settings
.
lastVisited
,
this
.
args
.
_
&&
this
.
args
.
_
.
length
>
0
?
{
url
:
this
.
urlify
(
this
.
args
.
_
[
0
])
}
:
undefined
,
])
const
[
response
,
options
]
=
await
Promise
.
all
([
await
this
.
getUtf8Resource
(
this
.
rootPath
,
`src/node/vscode/workbench
${
!
this
.
isDev
?
"
-build
"
:
""
}
.html`
),
this
.
initialize
({
args
:
this
.
args
,
query
:
route
.
query
,
remoteAuthority
:
request
.
headers
.
host
as
string
,
s
ettings
,
s
tartPath
,
}),
])
this
.
workbenchOptions
=
options
if
(
options
.
startPath
)
{
if
(
startPath
)
{
this
.
settings
.
write
({
lastVisited
:
{
path
:
options
.
startPath
.
path
,
workspace
:
options
.
startPath
.
workspace
,
},
lastVisited
:
startPath
,
})
}
...
...
@@ -201,4 +210,40 @@ export class VscodeHttpProvider extends HttpProvider {
response
.
content
=
response
.
content
.
replace
(
/{{COMMIT}}/g
,
this
.
options
.
commit
).
replace
(
/{{ERROR}}/g
,
message
)
return
response
}
/**
* Choose the first valid path. If `workspace` is undefined then either a
* workspace or a directory are acceptable. Otherwise it must be a file if a
* workspace or a directory otherwise.
*/
private
async
getFirstValidPath
(
startPaths
:
Array
<
{
url
?:
string
|
string
[];
workspace
?:
boolean
}
|
undefined
>
):
Promise
<
StartPath
|
undefined
>
{
for
(
let
i
=
0
;
i
<
startPaths
.
length
;
++
i
)
{
const
startPath
=
startPaths
[
i
]
if
(
!
startPath
)
{
continue
}
const
paths
=
typeof
startPath
.
url
===
"
string
"
?
[
startPath
.
url
]
:
startPath
.
url
||
[]
for
(
let
j
=
0
;
j
<
paths
.
length
;
++
j
)
{
const
u
=
url
.
parse
(
paths
[
j
])
try
{
if
(
!
u
.
pathname
)
{
throw
new
Error
(
`
${
paths
[
j
]}
is not a valid URL`
)
}
const
stat
=
await
fs
.
stat
(
u
.
pathname
)
if
(
typeof
startPath
.
workspace
===
"
undefined
"
||
startPath
.
workspace
!==
stat
.
isDirectory
())
{
return
{
url
:
u
.
href
,
workspace
:
!
stat
.
isDirectory
()
}
}
}
catch
(
error
)
{
logger
.
warn
(
error
.
message
)
}
}
}
return
undefined
}
private
urlify
(
p
:
string
):
string
{
return
"
vscode-remote://host
"
+
path
.
resolve
(
p
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录