-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: finalize project info detection
- Loading branch information
1 parent
80e4fd1
commit 79c336e
Showing
27 changed files
with
479 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import path from 'path' | ||
import { Uri, window, workspace } from 'vscode' | ||
|
||
import { InternalError } from './InternalError' | ||
import { UserError } from './UserError' | ||
import { getWorkspaceRootPath } from '../utils/getWorkspaceRootPath' | ||
|
||
export class DocumentInfo { | ||
#absolutePath: string | ||
#relativePath: string | ||
|
||
constructor() { | ||
const editor = window.activeTextEditor | ||
if (!editor) { | ||
throw new UserError('No active text editor.') | ||
} | ||
|
||
const workspaceRootPath = getWorkspaceRootPath() | ||
|
||
this.#absolutePath = editor.document.uri.fsPath | ||
this.#relativePath = path.relative(workspaceRootPath, this.#absolutePath) | ||
} | ||
|
||
get absolutePath(): string { | ||
return this.#absolutePath | ||
} | ||
|
||
get relativePath(): string { | ||
return this.#relativePath | ||
} | ||
|
||
async getSource(): Promise<string> { | ||
try { | ||
const textDocument = await workspace.openTextDocument(Uri.file(this.absolutePath)) | ||
|
||
return textDocument.getText() | ||
} catch (err) { | ||
throw new InternalError(`Error reading document: ${this.absolutePath}`, err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { WebSocketServer } from 'ws' | ||
|
||
import { InternalError } from './InternalError' | ||
import { stateManager } from './stateManager' | ||
import { State } from '../types' | ||
import { updateStateStatusBarItem } from '../utils/updateStateStatusBarItem' | ||
|
||
class Server { | ||
#webSocketServer: WebSocketServer | undefined | ||
|
||
start() { | ||
try { | ||
if (this.#webSocketServer) { | ||
return | ||
} | ||
|
||
this.#webSocketServer = new WebSocketServer({ port: 4242 }) | ||
|
||
this.#webSocketServer.on('connection', webSocket => { | ||
stateManager.clients.add(webSocket) | ||
updateStateStatusBarItem() | ||
|
||
// webSocket.on('message', message => { | ||
// console.debug(`New message received: ${message}.`) | ||
// }) | ||
|
||
webSocket.on('close', () => { | ||
stateManager.clients.delete(webSocket) | ||
updateStateStatusBarItem() | ||
}) | ||
}) | ||
|
||
stateManager.state = State.RUNNING | ||
updateStateStatusBarItem() | ||
} catch (err) { | ||
throw new InternalError('WebSocket server failed to start.', err) | ||
} | ||
} | ||
|
||
stop() { | ||
try { | ||
if (!this.#webSocketServer) { | ||
return | ||
} | ||
|
||
this.#webSocketServer.close(err => { | ||
if (err) { | ||
throw new InternalError('WebSocket server failed to stop.', err) | ||
} | ||
|
||
this.#webSocketServer = undefined | ||
stateManager.state = State.STOPPED | ||
updateStateStatusBarItem() | ||
}) | ||
} catch (err) { | ||
throw new InternalError('WebSocket server failed to stop.', err) | ||
} | ||
} | ||
} | ||
|
||
export const server = new Server() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.