Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Nov 8, 2024
1 parent 9582a58 commit 78380de
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 90 deletions.
28 changes: 11 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -442,23 +442,17 @@
"owner": "juvixerror",
"source": "Juvix Error",
"fileLocation": "autoDetect",
"pattern": [
{
"kind": "location",
"regexp": "^(.+):(\\d+)(?:-(\\d+))?:(\\d+)-(\\d+): (\\w+).*",
"file": 1,
"line": 2,
"endLine": 3,
"column": 4,
"endColumn": 5,
"severity": 6
},
{
"regexp": "(.*)",
"message": 1,
"loop": true
}
]
"pattern": {
"kind": "location",
"regexp": "^(.+):(\\d+)(?:-(\\d+))?:(\\d+)-(\\d+):\\s+(\\w+):(.*)$",
"file": 1,
"line": 2,
"endLine": 3,
"column": 4,
"endColumn": 5,
"severity": 6,
"message": 7
}
}
],
"commands": [
Expand Down
17 changes: 6 additions & 11 deletions src/check.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import * as vscode from 'vscode';
import * as user from './config';
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, typecheckTask: vscode.Task) {
const config = new user.JuvixConfig();

switch (config.typecheckOn()) {
case 'change':
context.subscriptions.push(
vscode.workspace.onDidChangeTextDocument(e => {
vscode.workspace.onDidChangeTextDocument(async e => {
const doc = e.document;
const activeEditor = vscode.window.activeTextEditor;
if (activeEditor && activeEditor.document === doc && isJuvixFile(doc))
vscode.tasks.executeTask(typecheckTask);
await vscode.tasks.executeTask(typecheckTask);
}),
);
break;
case 'save':
context.subscriptions.push(
vscode.workspace.onDidSaveTextDocument(doc => {
vscode.workspace.onDidSaveTextDocument(async doc => {
const activeEditor = vscode.window.activeTextEditor;
if (activeEditor && activeEditor.document === doc && isJuvixFile(doc))
vscode.tasks.executeTask(typecheckTask);
if (activeEditor && activeEditor.document === doc && isJuvixFile(doc)) {
await vscode.tasks.executeTask(typecheckTask);
}
}),
);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/highlighting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export class Highlighter implements vscode.DocumentSemanticTokensProvider {
? tk.interval.length
: tk.interval.endCol
: contentLines[l].length;
// lineLength represent the number of symbols we can see on the screen.
// lineLength represents the number of symbols we can see on the screen.
// However, in js, length for unicode symbols works not as expected, but
// rather shows the code units number.
// So we need to actually calculate all the code units.
Expand Down
1 change: 0 additions & 1 deletion src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export async function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(initDisp);

const disp = vscode.tasks.onDidEndTaskProcess(e => {

if (e.execution.task.name === task.name) {
if (e.exitCode === 0) {
showExecResultJuvixStatusBar(true, useCmdName, '');
Expand Down
30 changes: 0 additions & 30 deletions src/utils/autorunDisposable.ts

This file was deleted.

30 changes: 0 additions & 30 deletions src/utils/base.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import { spawn, spawnSync } from 'child_process';
import * as vscode from 'vscode';
import { Mutex } from 'async-mutex';
Expand Down Expand Up @@ -81,30 +78,3 @@ 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 {
const { file, line, begin_col, end_col, err_type, msg } = regexJuvixError.exec(output)!.groups!;
if (!msg || !line || !begin_col) return undefined;
const range = new vscode.Range(
new vscode.Position(parseInt(line) - 1, parseInt(begin_col) - 1),
new vscode.Position(parseInt(line) - 1, parseInt(end_col ?? begin_col) - 1),
);
let severity;
switch (err_type) {
case 'error':
severity = vscode.DiagnosticSeverity.Error;
break;
case 'warning':
severity = vscode.DiagnosticSeverity.Warning;
break;
case 'info':
severity = vscode.DiagnosticSeverity.Information;
break;
}
const diag = new vscode.Diagnostic(range, msg, severity);
diag.source = 'Juvix';
return diag;
}

0 comments on commit 78380de

Please sign in to comment.