Skip to content

Commit

Permalink
Put temporary files for LSP server in a proper temp directory. Also a…
Browse files Browse the repository at this point in the history
…dded additional debugging instructions.
  • Loading branch information
mcoblenz committed Oct 22, 2020
1 parent 198094a commit bda0fac
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
6 changes: 4 additions & 2 deletions obs-vscode-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ Compiling:
* npm run compile

To develop the extension/LSP:
* code -n . (to open the project in vscode)
* code -n . (to open the project in vscode)
* npm run compile to rebuild (VS Code does not automatically rebuild the extension when you run the debugger)
* Go to the "Run" menu on the left
* First, start "Launch client"
* First, start "Launch client". Or, to see server messages, instead choose "Client + Server" and skip "Attach to server" below.
* The extension will open in a new VSCode window
* Now select "Attach to server"
* You can now trigger breakpoints, etc.
* Log to console from server with console.log. Messages appear in the "Attach to server" section of the Debug Console in the host VSCode (not the one being debugged).

To install:
* vsce package
Expand Down
7 changes: 6 additions & 1 deletion obs-vscode-extension/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ async function validateTextDocument(change: TextDocumentChangeEvent<TextDocument
// Create temporary file containing the current set of changes
// TODO: Modify obsidianc to accept source code via stdin instead
// Note: obsidianc crashes if the source file begins with a dot
const tmpName = os.tmpdir() + "/ObsidianLSPTmp.obs"
const osTmpDir = os.tmpdir();
const { sep } = require('path');
const tmpDir = await fs.mkdtemp(`${osTmpDir}${sep}`);

const tmpName = `${tmpDir}${sep}ObsidianLSPTmp.obs`;
console.log(`tmpFile: ${tmpName}`);
const tmpFile = await fs.open(tmpName, "w+");
await tmpFile.write(change.document.getText(), 0);
tmpFile.close();
Expand Down
42 changes: 22 additions & 20 deletions obs-vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,29 @@ export function activate(context: vscode.ExtensionContext) {
// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
let compileCommand = vscode.commands.registerCommand('extension.compileObsidian', () => {
// The code you place here will be executed every time your command is executed
let task = getCompilationTask();
if (task != undefined) {
vscode.tasks.executeTask(task as vscode.Task).then(
compilationExecution => vscode.tasks.onDidEndTaskProcess(((e) => {
if (e.execution.task == task) {
if (e.exitCode == 0) {
vscode.window.showInformationMessage('Compilation succeeded.');
}
else {
vscode.window.showInformationMessage('Compilation failed.');
}
}
})
))
}
}
);

context.subscriptions.push(compileCommand);
// MJC: this is commented out for now because the LSP server makes manual compilation unnecessary.
// let compileCommand = vscode.commands.registerCommand('extension.compileObsidian', () => {
// // The code you place here will be executed every time your command is executed
// let task = getCompilationTask();
// if (task != undefined) {
// vscode.tasks.executeTask(task as vscode.Task).then(
// compilationExecution => vscode.tasks.onDidEndTaskProcess(((e) => {
// if (e.execution.task == task) {
// if (e.exitCode == 0) {
// vscode.window.showInformationMessage('Compilation succeeded.');
// }
// else {
// vscode.window.showInformationMessage('Compilation failed.');
// }
// }
// })
// ))
// }
// }
// );

// context.subscriptions.push(compileCommand);

let compileClientCommand = vscode.commands.registerCommand('extension.compileObsidianClient', () => {
// The code you place here will be executed every time your command is executed
Expand Down

0 comments on commit bda0fac

Please sign in to comment.