Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix documentation viewer #91

Merged
merged 23 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ export class JuvixConfig {
const juvixBuildDir = buildDir.toString();
try {
if (fs.existsSync(juvixBuildDir)) {
debugChannel.info(`Directory exists: ${juvixBuildDir}`);
return juvixBuildDir;
} else {
debugChannel.info(`Directory does not exist: ${juvixBuildDir}`);
const tmpJuvixDir = useTmpDir();
return tmpJuvixDir
}
Expand Down
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as codelens from './codelens';
export async function activate(context: vscode.ExtensionContext) {
debugChannel.clear();
statusBar.activate(context);
codelens.activate(context);
syntaxHighlighter.activate(context);
goToDefinition.activate(context);
hoverInfo.activate(context);
Expand Down
44 changes: 11 additions & 33 deletions src/judoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import * as fs from 'fs';
import { debugChannel } from './utils/debug';
import { JuvixConfig } from './config';
import { isJuvixFile } from './utils/base';
import { juvixRoot } from './root';
import * as path from 'path';
import { getModuleName } from './module';

export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(
Expand Down Expand Up @@ -65,20 +66,17 @@ export class JudocPanel {

private _panel: vscode.WebviewPanel;
private _disposables: vscode.Disposable[] = [];
// public readonly htmlFolder : string;

public static createOrShow(onlySource = false) {
this.onlySource = onlySource;
const editor = vscode.window.activeTextEditor;
if (!editor || !isJuvixFile(editor.document)) return;
this.juvixDocument = editor.document;
// If we already have a panel, show it.

if (JudocPanel.currentPanel) {
JudocPanel.currentPanel._panel.reveal();
return;
}

// Otherwise, create a new panel.
const panel = vscode.window.createWebviewPanel(
JudocPanel.viewType,
'Html preview',
Expand All @@ -99,7 +97,6 @@ export class JudocPanel {

private constructor(panel: vscode.WebviewPanel, _htmlFolder?: string) {
this._panel = panel;
// this.htmlFolder = htmlFolder;

this._disposables.push(
vscode.workspace.onDidSaveTextDocument(document => {
Expand All @@ -112,15 +109,6 @@ export class JudocPanel {
})
);

// this._disposables.push(
// vscode.workspace.onDidCloseTextDocument((document) => {
// if (document === JudocPanel.juvixDocument) {
// this._panel.dispose();
// // this.dispose();
// }
// })
// );

this._disposables.push(
vscode.workspace.onDidOpenTextDocument(document => {
if (!isJuvixFile(document)) return;
Expand Down Expand Up @@ -204,30 +192,23 @@ export class JudocPanel {
const doc = JudocPanel.juvixDocument;
if (!doc || (doc && !isJuvixFile(doc))) return;

const docFolder = vscode.workspace.getWorkspaceFolder(doc.uri);
if (!docFolder) return;
const config = new JuvixConfig();

// debugChannel.info("htmlFolder> " + this.htmlFolder);

// const judocDocFolderUri = vscode.Uri.file(this.htmlFolder);
// const judocDocFolderUri = vscode.Uri.file(config.getInternalBuildDir());
const judocDocFolderUri = vscode.Uri.joinPath(docFolder.uri, 'html');
// const buildDir = config.getInternalBuildDir();
const fileName = doc.fileName;
const parsedFilepath = path.parse(fileName);
const folderDocument = path.join(parsedFilepath.dir, 'docs', path.sep);
const judocDocFolderUri = vscode.Uri.file(folderDocument);

const { spawnSync } = require('child_process');

const vscodePrefix =
webview.asWebviewUri(judocDocFolderUri).toString() + '/';

webview.asWebviewUri(judocDocFolderUri).toString();
const config = new JuvixConfig();
const judocCall = [
config.getJuvixExec(),
'--internal-build-dir',
judocDocFolderUri.fsPath,
'html',
JudocPanel.onlySource ? '--only-source' : '',
'--output-dir',
// this.htmlFolder,
judocDocFolderUri.fsPath,
'--non-recursive',
'--prefix-assets',
Expand All @@ -236,6 +217,7 @@ export class JudocPanel {
vscodePrefix,
doc.uri.fsPath,
].join(' ');

debugChannel.info('Judoc call', judocCall);

const ls = spawnSync(judocCall, {
Expand All @@ -248,11 +230,7 @@ export class JudocPanel {
debugChannel.error('Judoc failed', errMsg);
throw new Error(errMsg);
}
const projRoot = juvixRoot();
const htmlFilename = doc.uri.fsPath
.replace(projRoot, '')
.replace('/', '.')
.replace('.juvix', '.html');
const htmlFilename = getModuleName(doc) + '.html';

const htmlByJudocForDoc = vscode.Uri.joinPath(
judocDocFolderUri,
Expand Down
3 changes: 1 addition & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import * as vscode from 'vscode';
import { juvixRoot, globalJuvixRoot, isUsingGlobalRoot } from './root';
import { juvixRoot, isUsingGlobalRoot } from './root';
import * as path from 'path';
import { isJuvixFile } from './utils/base';

Expand All @@ -25,5 +25,4 @@ export function getModuleName(document: vscode.TextDocument): string | undefined
}
return moduleName;


}
1 change: 0 additions & 1 deletion src/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export function juvixRoot() {
return undefined;
}


export function globalJuvixRoot() : string {
const juvixVersion = getInstalledNumericVersion();
const homeUserPath = process.env.HOME;
Expand Down
Loading