Skip to content

Commit

Permalink
refactor: rely on the pygls.server.cwd setting
Browse files Browse the repository at this point in the history
Rather than try and "guess" the path to `examples/servers` let's just
set it via a config option which should be more reliable
  • Loading branch information
alcarney committed May 24, 2024
1 parent 3487ed9 commit 5fe2e7c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
29 changes: 20 additions & 9 deletions .vscode/extensions/pygls-playground/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,22 +268,33 @@ async function executeServerCommand() {
}

/**
* If the user has explicitly provided a src directory use that.
* Otherwise, fallback to the examples/servers directory.
*
* @returns The working directory from which to launch the server
*/
function getCwd(): string {
const config = vscode.workspace.getConfiguration("pygls.server")
const cwd = config.get<string>('cwd')
if (cwd) {
return cwd
let cwd = config.get<string>('cwd')
if (!cwd) {
const message = "Please set a working directory via the `pygls.server.cwd` setting"
logger.error(message)
throw new Error(message)
}

const serverDir = path.resolve(
path.join(__dirname, "..", "..", "..", "..", "examples", "servers")
)
return serverDir
// Check for ${workspaceFolder} etc.
const match = cwd.match(/^\${(\w+)}/)
if (match && (match[1] === 'workspaceFolder' || match[1] === 'workspaceRoot')) {
if (!vscode.workspace.workspaceFolders) {
const message = "The 'pygls-playground' extension requires an open workspace"
logger.error(message)
throw new Error(message)
}

// Assume a single workspace...
const workspaceFolder = vscode.workspace.workspaceFolders[0].uri.fsPath
cwd = cwd.replace(match[0], workspaceFolder)
}

return cwd
}

/**
Expand Down
8 changes: 2 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@
"pygls.server.debug": false,
// "pygls.server.debugHost": "localhost",
// "pygls.server.debugPort": 5678,
"pygls.server.launchScript": "formatting.py",
"pygls.server.launchScript": "formatting.py", // This is relative to `pygls.server.cwd`
"pygls.server.cwd": "${workspaceFolder}/examples/servers",
"pygls.trace.server": "off",
"pygls.client.documentSelector": [
// {
// "scheme": "file",
// "language": "json"
// }
// Uncomment to use code_actions or inlay_hints servers
{
"scheme": "file",
"language": "plaintext"
Expand Down

0 comments on commit 5fe2e7c

Please sign in to comment.