Skip to content
This repository was archived by the owner on Jul 2, 2023. It is now read-only.
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
out
node_modules
node_modules
typings
168 changes: 100 additions & 68 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,71 +1,103 @@
{
"name": "erlang-otp",
"displayName": "Erlang/OTP",
"description": "Erlang/OTP support with syntax highlighting, auto-indent and snippets",
"version": "0.2.1",
"author": {
"name": "Yuce Tekol"
},
"publisher": "yuce",
"license": "SEE LICENSE IN LICENSE.md",
"engines": {
"vscode": "^0.10.6"
},
"categories": [
"Languages",
"Snippets"
],
"activationEvents": [
"onLanguage:erlang"
],
"main": "./out/src/extension",
"contributes": {
"languages": [{
"id": "erlang",
"aliases": ["Erlang", "erlang"],
"extensions": [".erl", ".hrl", ".yrl", ".escript", ".app.src", ".config"],
"filenames": [
"rebar.lock"
]
}],
"grammars": [{
"language": "erlang",
"scopeName": "source.erlang",
"path": "./syntaxes/erlang.tmLanguage"
}],
"snippets": [
{
"language": "erlang",
"path": "./snippets/erlang.json"
}
"name": "erlang-otp",
"displayName": "Erlang/OTP",
"description": "Erlang/OTP support with syntax highlighting, auto-indent and snippets",
"version": "0.2.1",
"author": {
"name": "Yuce Tekol"
},
"publisher": "yuce",
"license": "SEE LICENSE IN LICENSE.md",
"engines": {
"vscode": "^0.10.6"
},
"categories": [
"Languages",
"Snippets"
],
"activationEvents": [
"onLanguage:erlang"
],
"main": "./out/src/extension",
"contributes": {
"languages": [
{
"id": "erlang",
"aliases": [
"Erlang",
"erlang"
],
"configuration": {
"title": "Erlang configuration",
"properties": {
"erlang.enableExperimentalAutoComplete": {
"type": "boolean",
"default": false,
"description": "Enables experimental auto completion for Erlang standard library"
}
}
"extensions": [
".erl",
".hrl",
".yrl",
".escript",
".app.src",
".config"
],
"filenames": [
"rebar.lock"
]
}
],
"grammars": [
{
"language": "erlang",
"scopeName": "source.erlang",
"path": "./syntaxes/erlang.tmLanguage"
}
],
"snippets": [
{
"language": "erlang",
"path": "./snippets/erlang.json"
}
],
"configuration": {
"title": "Erlang configuration",
"properties": {
"erlang.enableExperimentalAutoComplete": {
"type": "boolean",
"default": false,
"description": "Enables experimental auto completion for Erlang standard library"
},
"erlang.escriptPath": {
"type": "string",
"default": "escript",
"description": "escriptPath"
},
"erlang.rebar3Path": {
"type": "string",
"default": "rebar3",
"description": "rebar3Path"
},
"erlang.erlangPath": {
"type": "string",
"default": "erl",
"description": "erlangPath"
}
},
"scripts": {
"vscode:prepublish": "node ./node_modules/vscode/bin/compile",
"compile": "node ./node_modules/vscode/bin/compile -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install"
},
"devDependencies": {
"typescript": "^1.7.5",
"vscode": "^0.11.0"
},
"repository": {
"type": "git",
"url": "https://github.com/yuce/erlang-vscode"
},
"icon": "images/erlang.png",
"bugs": {
"url": "https://github.com/yuce/erlang-vscode/issues"
},
"homepage": "https://github.com/yuce/erlang-vscode/README.md"
}
}
}
},
"scripts": {
"vscode:prepublish": "node ./node_modules/vscode/bin/compile",
"compile": "node ./node_modules/vscode/bin/compile -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install"
},
"devDependencies": {
"typescript": "^1.7.5",
"vscode": "^0.11.0"
},
"dependencies": {
"diff": "^3.0.1"
},
"repository": {
"type": "git",
"url": "https://github.com/yuce/erlang-vscode"
},
"icon": "images/erlang.png",
"bugs": {
"url": "https://github.com/yuce/erlang-vscode/issues"
},
"homepage": "https://github.com/yuce/erlang-vscode/README.md"
}
52 changes: 52 additions & 0 deletions priv/erl_tidy.escript
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env escript
%% -*- erlang -*-
%%! -smp enable -sname erl_tidy debug verbose

-mode(compile).
-export([main/1]).

%% erl_tidy.escript: does not support HRL ESCRIPT APP.SRC.

main([]) ->
io:format(standard_error
,"Usage: ~s <ERL files or folders>\n"
,[escript:script_name()]
),
halt(1);
main(Files) ->
tidy_files(Files).

%% Internals

tidy_files(Paths) ->
lists:foreach(fun tidy/1, Paths).

printer(AST, Options) ->
erl_prettypr:format(AST, [{paper, 115}
,{ribbon, 100}
| Options
]).

tidy(Path) ->
case {filelib:is_regular(Path), filelib:is_dir(Path)} of
{true, _} ->
case filename:extension(Path) of
".erl" ->
erl_tidy:file(Path, [{keep_unused, true} ,{stdout, true}, {printer, fun printer/2}]);
_ ->
skip(Path)
end;
{_, true} ->
RegExp = "\\.erl$",
Paths = filelib:fold_files(Path, RegExp, true, fun cons/2, []),
tidy_files(Paths);
_ ->
skip(Path)
end.

cons(H, T) -> [H | T].

skip(Path) ->
io:format(standard_error, "Skipping ~s\n", [Path]).

%% End of Module
20 changes: 20 additions & 0 deletions priv/fmt_test.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-module(binary_string).
-author("fireflyc").

%% API
-export([to_decimal/1]).

to_decimal(String) ->
try
{_, Result} = lists:foldr(fun to_decimal/2, {0, 0}, String),
Result

catch
_:_ -> 0

end.



to_decimal($0, {N, Acc}) -> {N + 1, Acc};
to_decimal($1, {N, Acc}) -> {N + 1, Acc + trunc(math:pow(2, N))}.
126 changes: 126 additions & 0 deletions src/common/edit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@

import * as vscode from 'vscode';
import * as jsDiff from 'diff';

export interface FilePatch {
fileName: string;
edits: Edit[];
}

export enum EditTypes { EDIT_DELETE, EDIT_INSERT, EDIT_REPLACE };

export class Edit {
action: number;
start: vscode.Position;
end: vscode.Position;
text: string;

constructor(action: number, start: vscode.Position) {
this.action = action;
this.start = start;
this.text = '';
}

// Creates TextEdit for current Edit
apply(): vscode.TextEdit {
switch (this.action) {
case EditTypes.EDIT_INSERT:
return vscode.TextEdit.insert(this.start, this.text);

case EditTypes.EDIT_DELETE:
return vscode.TextEdit.delete(new vscode.Range(this.start, this.end));

case EditTypes.EDIT_REPLACE:
return vscode.TextEdit.replace(new vscode.Range(this.start, this.end), this.text);
}
}

// Applies Edit using given TextEditorEdit
applyUsingTextEditorEdit(editBuilder: vscode.TextEditorEdit): void {
switch (this.action) {
case EditTypes.EDIT_INSERT:
editBuilder.insert(this.start, this.text);
break;

case EditTypes.EDIT_DELETE:
editBuilder.delete(new vscode.Range(this.start, this.end));
break;

case EditTypes.EDIT_REPLACE:
editBuilder.replace(new vscode.Range(this.start, this.end), this.text);
break;
}
}

// Applies Edits to given WorkspaceEdit
applyUsingWorkspaceEdit(workspaceEdit: vscode.WorkspaceEdit, fileUri: vscode.Uri): void {
switch (this.action) {
case EditTypes.EDIT_INSERT:
workspaceEdit.insert(fileUri, this.start, this.text);
break;

case EditTypes.EDIT_DELETE:
workspaceEdit.delete(fileUri, new vscode.Range(this.start, this.end));
break;

case EditTypes.EDIT_REPLACE:
workspaceEdit.replace(fileUri, new vscode.Range(this.start, this.end), this.text);
break;
}
}
}


export function getEdits(fileName: string, oldStr: string, newStr: string): FilePatch {
if (process.platform === 'win32') {
oldStr = oldStr.split('\r\n').join('\n');
newStr = newStr.split('\r\n').join('\n');
}
let unifiedDiffs: jsDiff.IUniDiff = jsDiff.structuredPatch(fileName, fileName, oldStr, newStr, '', '');
let filePatches: FilePatch[] = parseUniDiffs([unifiedDiffs]);
return filePatches[0];
}

function parseUniDiffs(diffOutput: jsDiff.IUniDiff[]): FilePatch[] {
let filePatches: FilePatch[] = [];
diffOutput.forEach((uniDiff: jsDiff.IUniDiff) => {
let edit: Edit = null;
let edits: Edit[] = [];
uniDiff.hunks.forEach((hunk: jsDiff.IHunk) => {
let startLine = hunk.oldStart;
hunk.lines.forEach((line) => {
switch (line.substr(0, 1)) {
case '-':
if (edit == null) {
edit = new Edit(EditTypes.EDIT_DELETE, new vscode.Position(startLine - 1, 0));
}
edit.end = new vscode.Position(startLine, 0);
startLine++;
break;
case '+':
if (edit == null) {
edit = new Edit(EditTypes.EDIT_INSERT, new vscode.Position(startLine - 1, 0));
} else if (edit.action === EditTypes.EDIT_DELETE) {
edit.action = EditTypes.EDIT_REPLACE;
}
edit.text += line.substr(1) + '\n';
break;
case ' ':
startLine++;
if (edit != null) {
edits.push(edit);
}
edit = null;
break;
}
});
if (edit != null) {
edits.push(edit);
}
});
filePatches.push({ fileName: uniDiff.oldFileName, edits: edits });
});

return filePatches;

}
Loading