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

Add injection grammars for packages, validation and overloads #132

Merged
merged 27 commits into from Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d249f0f
Add MATLAB support library injections
Jul 2, 2021
d4646e5
Sync MATLAB grammar submodule
Jul 2, 2021
0d2aa47
Validate Oniguruma patterns in injection grammars
Jul 2, 2021
beda3f1
Add missing functions (images, errors)
Jul 2, 2021
8a228b3
Update dependencies
Jul 2, 2021
193c747
Remove duplicated constants from injection grammar
Jul 5, 2021
57c3fb7
Fix builtin grammar injection selector
Jul 5, 2021
8a0975e
Sync submodule with mathworks/MATLAB-Language-grammar#38
Jul 7, 2021
789418c
Fix typo in builtin.matlab.injection
Jul 7, 2021
4531402
Highlight readwrite variables and properties
Jul 7, 2021
fa24010
Add and enforce Editorconfig
Jul 7, 2021
71f0d6f
Use support.function.io to avoid `storage` clashes
Jul 7, 2021
7bb5403
Enforce editorconfig in readwrite injection
Jul 9, 2021
f0325c8
Add toolboxes and simplify regexes
Jul 11, 2021
7fd5b23
Undeprecate figure.Visible
Jul 13, 2021
a5244d9
Undeprecate generic properties
Jul 19, 2021
ef15fcc
Fix package.json whitespace
Jul 20, 2021
d18d3e7
Add matlab.io scientific dataset packages
Jul 22, 2021
eab1f7a
Fix builtin functions with identifier/dot prefixes
Jul 22, 2021
d1b8e80
Fix readwrite injection selector
Jul 27, 2021
505327c
Prevent variables in command dualilty
Jul 29, 2021
b607cc3
Respect entities and shell highlighting
Jul 29, 2021
96f46e5
Exclude support library in shell highlighting
Jul 29, 2021
0d462c6
Fix variable injection patterns
Jul 29, 2021
f6563f1
Use two-space indent in source code
Jul 30, 2021
08f5d22
Undeprecate rm* functions
Jul 30, 2021
50c378c
Sync with mathworks/MATLAB-Language-grammar#39
Aug 3, 2021
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
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Top-most EditorConfig file
root = true

# Tab indentation
[*]
charset = utf-8
end_of_line = crlf
indent_style = space
indent_size = 2
insert_final_newline = true

# The indent size used in the `package.json` file cannot be changed
# https://github.com/npm/npm/pull/3180#issuecomment-16336516
[*.xml]
indent_style = tab
indent_size = 2
26 changes: 18 additions & 8 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,33 @@

// A task runner that calls a custom npm script that compiles the extension.
{
"version": "0.1.0",
"version": "2.0.0",

// we want to run npm
"command": "npm",

// the command is a shell script
"isShellCommand": true,

// show the output window only if unrecognized errors occur.
"showOutput": "silent",

// we run the custom script "compile" as defined in package.json
"args": ["run", "compile", "--loglevel", "silent"],

// The tsc compiler is started in watching mode
"isWatching": true,

// use the standard tsc in watch mode problem matcher to find compile problems in the output.
"problemMatcher": "$tsc-watch"
"problemMatcher": "$tsc-watch",
"tasks": [
{
"label": "npm",
"type": "shell",
"command": "npm",
"args": [
"run",
"compile",
"--loglevel",
"silent"
],
"isBackground": true,
"problemMatcher": "$tsc-watch",
"group": "build"
}
]
}
45 changes: 37 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "matlab",
"displayName": "Matlab",
"description": "MATLAB support for Visual Studio Code",
"version": "2.0.1",
"version": "2.1.0",
"publisher": "Gimly81",
"license": "SEE LICENSE IN LICENSE.md",
"license": "MIT",
"engines": {
"vscode": "^1.16.0"
},
Expand Down Expand Up @@ -48,8 +48,36 @@
"injectTo": [
"source.matlab"
],
"scopeName": "matlab-functions.injection",
"path": "./syntaxes/matlab-functions.tmLanguage"
"scopeName": "builtin.matlab.injection",
"path": "./syntaxes/builtin.matlab.injection.tmLanguage"
},
{
"injectTo": [
"source.matlab"
],
"scopeName": "overload.matlab.injection",
"path": "./syntaxes/overload.matlab.injection.tmLanguage"
},
{
"injectTo": [
"source.matlab"
],
"scopeName": "package.matlab.injection",
"path": "./syntaxes/package.matlab.injection.tmLanguage"
},
{
"injectTo": [
"source.matlab"
],
"scopeName": "readwrite.matlab.injection",
"path": "./syntaxes/readwrite.matlab.injection.tmLanguage"
},
{
"injectTo": [
"source.matlab"
],
"scopeName": "validation.matlab.injection",
"path": "./syntaxes/validation.matlab.injection.tmLanguage"
}
],
"snippets": [
Expand Down Expand Up @@ -101,11 +129,12 @@
"postinstall": "node ./node_modules/vscode/bin/install"
},
"devDependencies": {
"typescript": "^2.5.2",
"vscode": "^1.1.5",
"mocha": "^3.5.0",
"@types/mocha": "^2.2.42",
"@types/node": "^7.0.43",
"@types/mocha": "^2.2.42"
"@types/vscode": "^1.57.0",
"mocha": "^3.5.0",
"typescript": "^4.3.5",
"vscode-test": "^1.5.2"
},
"dependencies": {
"iconv-lite": "^0.4.19"
Expand Down
2 changes: 1 addition & 1 deletion src/PeekFileDefinitionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ export default class PeekFileDefinitionProvider implements vscode.DefinitionProv
return undefined;
});
}
}
}
128 changes: 64 additions & 64 deletions src/matlabDiagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,71 +9,71 @@ import { ERROR_IDS } from './errorsId';
import { window } from 'vscode';

export interface ICheckResult {
file: string;
line: number;
column: [number, number];
msg: string;
severity: string
file: string;
line: number;
column: [number, number];
msg: string;
severity: string
}

export function check(document: vscode.TextDocument, lintOnSave = true, mlintPath = ""): Promise<ICheckResult[]> {
var matlabLint = !lintOnSave ? Promise.resolve([]) : new Promise((resolve, reject) => {
var filename = document.uri.fsPath;

let matlabConfig = vscode.workspace.getConfiguration('matlab');

let args: string[] = ['-all', '-id'];
if (matlabConfig.has('linterConfig') && matlabConfig['linterConfig'] != null) {
args.push(`-config=${matlabConfig['linterConfig']}`);
}

args.push(filename);

let fileEncoding = 'utf8';
if (matlabConfig.has('linterEncoding') && matlabConfig['linterEncoding'] != null) {
fileEncoding = matlabConfig['linterEncoding'];
}

cp.execFile(
mlintPath,
args,
{ encoding: 'buffer' },
(err: Error, stdout, stderr) => {
try {
let errorsString = iconv.decode(stderr, fileEncoding);

var errors = errorsString.split('\n');

var ret: ICheckResult[] = [];

errors.forEach(error => {
var regex = /L (\d+) \(C (\d+)-?(\d+)?\): (\S+): (.*)/;
var match = regex.exec(error);

if (match != null) {
var [_, lineStr, startCol, endCol, idErrorWarn, msg] = match;
var line = +lineStr;

if (endCol == null) {
endCol = startCol;
}

if (ERROR_IDS.includes(idErrorWarn)) {
ret.push({ file: filename, line, column: [+startCol, +endCol], msg, severity: "error" });
}
else {
ret.push({ file: filename, line, column: [+startCol, +endCol], msg, severity: "warning" });
}
}
});

resolve(ret);
} catch (error) {
console.error(error);
reject(error);
}
});
});

return Promise.all([matlabLint]).then(resultSets => [].concat.apply([], resultSets));
var matlabLint = !lintOnSave ? Promise.resolve([]) : new Promise((resolve, reject) => {
var filename = document.uri.fsPath;

let matlabConfig = vscode.workspace.getConfiguration('matlab');

let args: string[] = ['-all', '-id'];
if (matlabConfig.has('linterConfig') && matlabConfig['linterConfig'] != null) {
args.push(`-config=${matlabConfig['linterConfig']}`);
}

args.push(filename);

let fileEncoding = 'utf8';
if (matlabConfig.has('linterEncoding') && matlabConfig['linterEncoding'] != null) {
fileEncoding = matlabConfig['linterEncoding'];
}

cp.execFile(
mlintPath,
args,
{ encoding: 'buffer' },
(err: Error, stdout, stderr) => {
try {
let errorsString = iconv.decode(stderr, fileEncoding);

var errors = errorsString.split('\n');

var ret: ICheckResult[] = [];

errors.forEach(error => {
var regex = /L (\d+) \(C (\d+)-?(\d+)?\): (\S+): (.*)/;
var match = regex.exec(error);

if (match != null) {
var [_, lineStr, startCol, endCol, idErrorWarn, msg] = match;
var line = +lineStr;

if (endCol == null) {
endCol = startCol;
}

if (ERROR_IDS.includes(idErrorWarn)) {
ret.push({ file: filename, line, column: [+startCol, +endCol], msg, severity: "error" });
}
else {
ret.push({ file: filename, line, column: [+startCol, +endCol], msg, severity: "warning" });
}
}
});

resolve(ret);
} catch (error) {
console.error(error);
reject(error);
}
});
});

return Promise.all([matlabLint]).then(resultSets => [].concat.apply([], resultSets));
}
Loading