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 24 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 = tab
Gimly marked this conversation as resolved.
Show resolved Hide resolved
insert_final_newline = true
tab_width = 4

# The indent size used in the `package.json` file cannot be changed
# https://github.com/npm/npm/pull/3180#issuecomment-16336516
[{*.yml,*.yaml,package.json}]
indent_style = space
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
128 changes: 64 additions & 64 deletions src/PeekFileDefinitionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,72 +5,72 @@ import { isUndefined } from 'util';

export default class PeekFileDefinitionProvider implements vscode.DefinitionProvider {

constructor() {}
constructor() {}

getComponentName(position: vscode.Position): String[] {
const doc = vscode.window.activeTextEditor.document;
const selection = doc.getWordRangeAtPosition(position);
const selectedText = doc.getText(selection);
let possibleFileNames = [];
possibleFileNames.push(selectedText + '.m');
return possibleFileNames;
}
getComponentName(position: vscode.Position): String[] {
const doc = vscode.window.activeTextEditor.document;
const selection = doc.getWordRangeAtPosition(position);
const selectedText = doc.getText(selection);
let possibleFileNames = [];
possibleFileNames.push(selectedText + '.m');
return possibleFileNames;
}

getNestedFuncPosition(position: vscode.Position): number[] {
const doc = vscode.window.activeTextEditor.document;
const selection = doc.getWordRangeAtPosition(position);
const selectedText = doc.getText(selection);
getNestedFuncPosition(position: vscode.Position): number[] {
const doc = vscode.window.activeTextEditor.document;
const selection = doc.getWordRangeAtPosition(position);
const selectedText = doc.getText(selection);

for (let lineNb = 0; lineNb < doc.lineCount; lineNb ++) {
const txtLine = doc.lineAt(lineNb);
if (!txtLine.isEmptyOrWhitespace) {
const content = txtLine.text;
const Colfunc = content.indexOf('function ');
const ColName1 = content.indexOf(selectedText + '(');
const ColName2 = content.indexOf(selectedText + ' (');
if (Colfunc != -1 && (ColName1 != -1 || ColName2 != -1)) {
return [lineNb, Colfunc];
}
}
}
return [];
}
for (let lineNb = 0; lineNb < doc.lineCount; lineNb ++) {
const txtLine = doc.lineAt(lineNb);
if (!txtLine.isEmptyOrWhitespace) {
const content = txtLine.text;
const Colfunc = content.indexOf('function ');
const ColName1 = content.indexOf(selectedText + '(');
const ColName2 = content.indexOf(selectedText + ' (');
if (Colfunc != -1 && (ColName1 != -1 || ColName2 != -1)) {
return [lineNb, Colfunc];
}
}
}
return [];
}

searchFilePath(fileName: String): Thenable<vscode.Uri[]> {
return vscode.workspace.findFiles(`**/${fileName}`, '**/node_modules'); // Returns promise
}
searchFilePath(fileName: String): Thenable<vscode.Uri[]> {
return vscode.workspace.findFiles(`**/${fileName}`, '**/node_modules'); // Returns promise
}

provideDefinition(
document: vscode.TextDocument,
position: vscode.Position,
token: vscode.CancellationToken
): Promise<vscode.Location | vscode.Location[]> {
let filePaths = [];
const componentNames = this.getComponentName(position);
const searchPathActions = componentNames.map(this.searchFilePath);
const searchPromises = Promise.all(searchPathActions); // pass array of promises
const posInFile = this.getNestedFuncPosition(position);
return searchPromises.then((paths) => {
filePaths = [].concat.apply([], paths);
if (filePaths.length) {
console.log(posInFile)
let allPaths = [];
filePaths.forEach(filePath => {
allPaths.push(new vscode.Location(vscode.Uri.file(`${filePath.path}`),new vscode.Position(0,1) ))
});
return allPaths;
} else {
if (posInFile.length) {
let allPaths = [];
allPaths.push(new vscode.Location(document.uri,new vscode.Position(posInFile[0],posInFile[1])));
return allPaths;
} else {
return undefined;
}
}
}, (reason) => {
return undefined;
});
}
}
provideDefinition(
document: vscode.TextDocument,
position: vscode.Position,
token: vscode.CancellationToken
): Promise<vscode.Location | vscode.Location[]> {
let filePaths = [];
const componentNames = this.getComponentName(position);
const searchPathActions = componentNames.map(this.searchFilePath);
const searchPromises = Promise.all(searchPathActions); // pass array of promises
const posInFile = this.getNestedFuncPosition(position);
return searchPromises.then((paths) => {
filePaths = [].concat.apply([], paths);
if (filePaths.length) {
console.log(posInFile)
let allPaths = [];
filePaths.forEach(filePath => {
allPaths.push(new vscode.Location(vscode.Uri.file(`${filePath.path}`),new vscode.Position(0,1) ))
});
return allPaths;
} else {
if (posInFile.length) {
let allPaths = [];
allPaths.push(new vscode.Location(document.uri,new vscode.Position(posInFile[0],posInFile[1])));
return allPaths;
} else {
return undefined;
}
}
}, (reason) => {
return undefined;
});
}
}
Loading