Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ca152e5

Browse files
committed
Address comments.
1 parent 32bedb4 commit ca152e5

File tree

4 files changed

+27
-31
lines changed

4 files changed

+27
-31
lines changed

‎patches/store-socket.diff‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Index: code-server/lib/vscode/src/vs/workbench/api/node/extHostExtensionService.
3434

3535
class NodeModuleRequireInterceptor extends RequireInterceptor {
3636

37-
@@ -79,6 +82,59 @@ export class ExtHostExtensionService ext
37+
@@ -79,6 +82,52 @@ export class ExtHostExtensionService ext
3838
await interceptor.install();
3939
performance.mark('code/extHost/didInitAPI');
4040

@@ -60,23 +60,16 @@ Index: code-server/lib/vscode/src/vs/workbench/api/node/extHostExtensionService.
6060
+ method: 'POST',
6161
+ headers: {
6262
+ 'content-type': 'application/json',
63-
+ 'accept': 'application/json'
6463
+ }
6564
+ };
6665
+ const req = _http.request(opts, (res) => {
67-
+ if (res.headers['content-type'] !== 'application/json') {
68-
+ reject('Error in response: Invalid content type: Expected \'application/json\', is: ' + res.headers['content-type']);
69-
+ return;
70-
+ }
71-
+
72-
+ res.setEncoding('utf8');
7366
+ res.on('error', reject);
7467
+ res.on('end', () => {
7568
+ try {
7669
+ if (res.statusCode === 200) {
77-
+ resolve();
70+
+ resolve();
7871
+ } else {
79-
+ reject(new Error('Unexpected status code: ' + res.statusCode));
72+
+ reject(new Error('Unexpected status code: ' + res.statusCode));
8073
+ }
8174
+ } catch (e: unknown) {
8275
+ reject(e);

‎src/node/app.ts‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import { isNodeJSErrnoException } from "./util"
1212
import { DEFAULT_SOCKET_PATH, EditorSessionManager, makeEditorSessionManagerServer } from "./vscodeSocket"
1313
import { handleUpgrade } from "./wsRouter"
1414

15-
type ListenOptions = Pick<Partial<DefaultedArgs>, "socket-mode" | "socket" | "port" | "host">
15+
type SocketOptions = { socket: string; "socket-mode"?: string }
16+
type ListenOptions = DefaultedArgs | SocketOptions
1617

1718
export interface App extends Disposable {
1819
/** Handles regular HTTP requests. */
@@ -25,10 +26,14 @@ export interface App extends Disposable {
2526
editorSessionManagerServer: http.Server
2627
}
2728

28-
export const listen = async (server: http.Server, { host, port, socket, "socket-mode": mode }: ListenOptions) => {
29-
if (socket) {
29+
const isSocketOpts = (opts: ListenOptions): opts is SocketOptions => {
30+
return !!(opts as SocketOptions).socket || !(opts as DefaultedArgs).host
31+
}
32+
33+
export const listen = async (server: http.Server, opts: ListenOptions) => {
34+
if (isSocketOpts(opts)) {
3035
try {
31-
await fs.unlink(socket)
36+
await fs.unlink(opts.socket)
3237
} catch (error: any) {
3338
handleArgsSocketCatchError(error)
3439
}
@@ -41,18 +46,20 @@ export const listen = async (server: http.Server, { host, port, socket, "socket-
4146
server.on("error", (err) => util.logError(logger, "http server error", err))
4247
resolve()
4348
}
44-
if (socket) {
45-
server.listen(socket, onListen)
49+
if (isSocketOpts(opts)) {
50+
server.listen(opts.socket, onListen)
4651
} else {
4752
// [] is the correct format when using :: but Node errors with them.
48-
server.listen(port, host!.replace(/^\[|\]$/g, ""), onListen)
53+
server.listen(opts.port, opts.host.replace(/^\[|\]$/g, ""), onListen)
4954
}
5055
})
5156

5257
// NOTE@jsjoeio: we need to chmod after the server is finished
5358
// listening. Otherwise, the socket may not have been created yet.
54-
if (socket && mode) {
55-
await fs.chmod(socket, mode)
59+
if (isSocketOpts(opts)) {
60+
if (opts["socket-mode"]) {
61+
await fs.chmod(opts.socket, opts["socket-mode"])
62+
}
5663
}
5764
}
5865

‎src/node/main.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,12 @@ export const runCodeServer = async (
121121
const app = await createApp(args)
122122
const protocol = args.cert ? "https" : "http"
123123
const serverAddress = ensureAddress(app.server, protocol)
124+
const sessionServerAddress = app.editorSessionManagerServer.address()
124125
const disposeRoutes = await register(app, args)
125126

126127
logger.info(`Using config file ${humanPath(os.homedir(), args.config)}`)
127128
logger.info(`${protocol.toUpperCase()} server listening on ${serverAddress.toString()}`)
129+
logger.info(`Session server listening on ${sessionServerAddress?.toString()}`)
128130

129131
if (args.auth === AuthType.Password) {
130132
logger.info(" - Authentication is enabled")

‎src/node/vscodeSocket.ts‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import express from "express"
33
import * as http from "http"
44
import * as os from "os"
55
import * as path from "path"
6+
import { HttpCode } from "../common/http"
67
import { listen } from "./app"
78
import { canConnect } from "./util"
89

@@ -46,15 +47,15 @@ export async function makeEditorSessionManagerServer(
4647
router.get("/session", async (req, res) => {
4748
const filePath = req.query.filePath as string
4849
if (!filePath) {
49-
res.status(400).send("filePath is required")
50+
res.status(HttpCode.BadRequest).send("filePath is required")
5051
return
5152
}
5253
try {
5354
const socketPath = await editorSessionManager.getConnectedSocketPath(filePath)
5455
const response: GetSessionResponse = { socketPath }
5556
res.json(response)
5657
} catch (error: unknown) {
57-
res.status(500).send(error)
58+
res.status(HttpCode.ServerError).send(error)
5859
}
5960
})
6061

@@ -108,7 +109,7 @@ export class EditorSessionManager {
108109
// Matches first.
109110
const aMatch = checkMatch(a)
110111
const bMatch = checkMatch(b)
111-
if (aMatch && bMatch) {
112+
if (aMatch === bMatch) {
112113
return 0
113114
}
114115
if (aMatch) {
@@ -118,7 +119,7 @@ export class EditorSessionManager {
118119
})
119120
}
120121

121-
asyncdeleteSession(socketPath: string): Promise<void> {
122+
deleteSession(socketPath: string): void {
122123
logger.debug(`Deleting session from session registry: ${socketPath}`)
123124
this.entries.delete(socketPath)
124125
}
@@ -131,19 +132,12 @@ export class EditorSessionManager {
131132
const candidates = this.getCandidatesForFile(filePath)
132133
let match: EditorSessionEntry | undefined = undefined
133134

134-
const toDelete = new Set<EditorSessionEntry>()
135135
for (const candidate of candidates) {
136136
if (await canConnect(candidate.socketPath)) {
137137
match = candidate
138138
break
139139
}
140-
toDelete.add(candidate)
141-
}
142-
143-
if (toDelete.size > 0) {
144-
for (const candidate of toDelete) {
145-
this.deleteSession(candidate.socketPath)
146-
}
140+
this.deleteSession(candidate.socketPath)
147141
}
148142

149143
return match?.socketPath

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /