Skip to content

Commit

Permalink
use task for typecheck-silent
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Nov 7, 2024
1 parent dcef5a2 commit 9582a58
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.2.4",
"version": "0.2.5",
"configurations": [
{
"name": "Run Extension",
Expand Down
2 changes: 1 addition & 1 deletion juvix.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.6.6
0.6.7
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "juvix-mode",
"version": "0.2.4",
"version": "0.2.5",
"license": "GPL-3.0",
"description": "Juvix Mode for VSCode",
"displayName": "Juvix",
Expand Down
68 changes: 5 additions & 63 deletions src/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,76 +4,22 @@

import * as vscode from 'vscode';
import * as user from './config';
import { isJuvixFile, runShellCommand, getDiagnosticFromError } from './utils/base';
import { isJuvixFile } from './utils/base';
import { logger } from './utils/debug';
import { setJuvixCommandStatusBarItem, inProgressJuvixCommandStatusBar, showExecResultJuvixStatusBar } from './statusbar';
import * as highlighting from './highlighting';

export async function activate(context: vscode.ExtensionContext, diagnosticCollection: vscode.DiagnosticCollection) {
export async function activate(context: vscode.ExtensionContext, typecheckTask: vscode.Task) {
const config = new user.JuvixConfig();

const command = 'juvix-mode.typecheck-silent';

const commandHandler = async (doc: vscode.TextDocument, content: string) => {
const activeEditor = vscode.window.activeTextEditor;

if (activeEditor && activeEditor.document == doc) {
if (doc && isJuvixFile(doc)) {
const filePath = doc.fileName;

const typecheckerCall = [
config.getJuvixExec(),
config.getGlobalFlags(),
'typecheck',
config.getTypeckeckFlags(),
filePath,
].join(' ');

inProgressJuvixCommandStatusBar('Typecheck');
const { stdout, stderr, status } = await runShellCommand(typecheckerCall, content);

if (status !== 0) {
showExecResultJuvixStatusBar(false, 'Typecheck', stderr);
const diag = getDiagnosticFromError(stderr);
if (diag)
diagnosticCollection.set(doc.uri, [diag]);
}
else {
showExecResultJuvixStatusBar(true, 'Typecheck', stdout);
diagnosticCollection.delete(doc.uri);
}
return { stdout, stderr, status };
}
}
return undefined;
};

context.subscriptions.push(
vscode.commands.registerCommand(command, commandHandler),
);


context.subscriptions.push(
vscode.workspace.onDidCloseTextDocument(doc => diagnosticCollection.delete(doc.uri))
);

context.subscriptions.push(
vscode.window.onDidChangeActiveTextEditor(_ => {
setJuvixCommandStatusBarItem();
}
));

switch (config.typecheckOn()) {
case 'change':
context.subscriptions.push(
vscode.workspace.onDidChangeTextDocument(e => {
const doc = e.document;
const activeEditor = vscode.window.activeTextEditor;
if (activeEditor && activeEditor.document === doc && isJuvixFile(doc))
vscode.commands.executeCommand(
'juvix-mode.typecheck-silent',
doc,
doc.getText(),
)
vscode.tasks.executeTask(typecheckTask);
}),
);
break;
Expand All @@ -82,11 +28,7 @@ export async function activate(context: vscode.ExtensionContext, diagnosticColle
vscode.workspace.onDidSaveTextDocument(doc => {
const activeEditor = vscode.window.activeTextEditor;
if (activeEditor && activeEditor.document === doc && isJuvixFile(doc))
vscode.commands.executeCommand(
'juvix-mode.typecheck-silent',
doc,
doc.getText(),
)
vscode.tasks.executeTask(typecheckTask);
}),
);
break;
Expand Down
4 changes: 0 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ export async function activate(context: vscode.ExtensionContext) {
];
modules.forEach(module => module.activate(context));

let juvixDiagnosticCollection = vscode.languages.createDiagnosticCollection('juvix');
check.activate(context, juvixDiagnosticCollection);
context.subscriptions.push(juvixDiagnosticCollection);

vscode.commands.executeCommand('setContext', 'juvix-mode:ready', true);
}
}
10 changes: 9 additions & 1 deletion src/highlighting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ map that associates a file path to the corresponding information for that file.
export async function activate(context: vscode.ExtensionContext) {
if (!config.enableSemanticSyntax()) return;
try {
const semanticTokensProvider = new Highlighter();
const highlighterProvider =
vscode.languages.registerDocumentSemanticTokensProvider(
{ language: 'Juvix', scheme: 'file' },
Expand Down Expand Up @@ -101,6 +100,13 @@ export const legend: vscode.SemanticTokensLegend = (function () {
})();

export class Highlighter implements vscode.DocumentSemanticTokensProvider {
private _onDidChangeSemanticTokens = new vscode.EventEmitter<void>();
public onDidChangeSemanticTokens = this._onDidChangeSemanticTokens.event;

public triggerRehighlighting(): void {
this._onDidChangeSemanticTokens.fire();
}

async provideDocumentSemanticTokens(
document: vscode.TextDocument,
_token: vscode.CancellationToken,
Expand Down Expand Up @@ -267,3 +273,5 @@ export class Highlighter implements vscode.DocumentSemanticTokensProvider {
return token;
}
}

export const semanticTokensProvider = new Highlighter();
13 changes: 12 additions & 1 deletion src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import * as vscode from 'vscode';
import * as user from './config';
import { logger } from './utils/debug';
import * as check from './check';
import { inProgressJuvixCommandStatusBar, showExecResultJuvixStatusBar } from './statusbar';

export const TASK_TYPE = 'Juvix';
Expand Down Expand Up @@ -37,6 +38,7 @@ export async function activate(context: vscode.ExtensionContext) {
const cmdName = task.name.replace(' ', '-');
let useCmdName;
if (cmdName === 'typecheck-silent') {
check.activate(context, task);
useCmdName = 'typecheck';
} else {
useCmdName = cmdName;
Expand Down Expand Up @@ -107,7 +109,13 @@ export class JuvixTaskProvider implements vscode.TaskProvider {
command: 'typecheck',
args: [config.getTypeckeckFlags(), '${file}'],
group: vscode.TaskGroup.Build,
reveal: vscode.TaskRevealKind.Silent,
reveal: vscode.TaskRevealKind.Always,
},
{
command: 'typecheck-silent',
args: [config.getTypeckeckFlags(), '${file}'],
group: vscode.TaskGroup.Build,
reveal: vscode.TaskRevealKind.Never,
},
{
command: 'compile',
Expand Down Expand Up @@ -227,6 +235,9 @@ export async function JuvixTask(
case 'update-dependencies':
exec = new vscode.ShellExecution(JuvixExec + `dependencies update`);
break;
case 'typecheck-silent':
exec = new vscode.ShellExecution(JuvixExec + ` typecheck ${fl}`);
break;
default:
exec = new vscode.ShellExecution(JuvixExec + ` ${input}`);
break;
Expand Down
1 change: 1 addition & 0 deletions src/utils/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export async function runShellCommand(command: string, input?: string): Promise<
});
}

// ^(.+):(\\d+)(?:-(\\d+))?:(\\d+)-(\\d+): (\\w+).*
const regexJuvixError = /(?<file>.*):(?<line>\d+):(?<begin_col>\d+)-?(?<end_col>\d+)?:\s(?<err_type>.*):\s?(?<msg>((\n|.)*))/g;

export function getDiagnosticFromError(output: string): vscode.Diagnostic | undefined {
Expand Down

0 comments on commit 9582a58

Please sign in to comment.