Skip to content

Commit

Permalink
remove unused configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
leftstick committed Oct 31, 2016
1 parent bf881b1 commit 349f0ce
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ The default format command `shift+alt+f` is overrided, so when you go with `Form
[vs-image]: http://vsmarketplacebadge.apphb.com/version/howardzuo.vscode-esformatter.svg
[install-url]: http://vsmarketplacebadge.apphb.com/installs/howardzuo.vscode-esformatter.svg
[rate-url]: http://vsmarketplacebadge.apphb.com/rating/howardzuo.vscode-esformatter.svg
[license-url]: https://img.shields.io/github/license/leftstick/vscode-esformatter.svg
[license-url]: https://img.shields.io/github/license/leftstick/vscode-esformatter.svg
7 changes: 4 additions & 3 deletions client/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ module.exports.connect = (context) => {
documentSelector: langs,
initializationOptions: function() {
let configuration = workspace.getConfiguration('files');
return {
eol: configuration.get('eol', '\n')
};
return {eol: configuration.get('eol', '\n')};
},
synchronize: {
configurationSection: ['files', 'esformatter']
},
initializationFailedHandler: function(error) {
client.error('Format code failed.', error);
Expand Down
18 changes: 6 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-esformatter",
"displayName": "esformatter",
"description": "An esformatter support plugin, which helps JavaScript developers beautify/format the code",
"version": "1.3.0",
"version": "1.3.1",
"publisher": "howardzuo",
"engines": {
"vscode": "^1.6.0"
Expand Down Expand Up @@ -31,13 +31,7 @@
"configuration": {
"type": "object",
"title": "Esformatter configuration",
"properties": {
"esformatter.formatOnSave": {
"type": "boolean",
"default": true,
"description": "Whether to format currently working editor while saving"
}
}
"properties": {}
}
},
"badges": [
Expand All @@ -62,10 +56,10 @@
},
"license": "SEE LICENSE IN LICENSE",
"devDependencies": {
"vscode": "^1.0.1"
"vscode": "^1.0.3"
},
"dependencies": {
"esformatter": "^0.9.6",
"esformatter": "^0.10.0",
"esformatter-add-trailing-commas": "^1.1.0",
"esformatter-align": "^0.2.3",
"esformatter-asi": "^0.5.2",
Expand All @@ -77,7 +71,7 @@
"esformatter-flow": "^1.0.1",
"esformatter-ignore": "^0.1.3",
"esformatter-jquery-chain": "^1.1.0",
"esformatter-jsx": "^7.0.1",
"esformatter-jsx": "^7.1.0",
"esformatter-limit-linebreaks": "0.0.3",
"esformatter-literal-notation": "^1.0.1",
"esformatter-parseint": "^1.0.3",
Expand All @@ -93,4 +87,4 @@
"vscode-languageclient": "^2.6.0",
"vscode-languageserver": "^2.6.0"
}
}
}
26 changes: 16 additions & 10 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ let connection = createConnection(new IPCMessageReader(process), new IPCMessageW
let documents = new TextDocuments();
documents.listen(connection);

let workspaceRoot, settings;
let settings;

connection.onInitialize((params) => {
workspaceRoot = params.rootPath;
connection.onInitialize(params => {
settings = params.initializationOptions;
return {
capabilities: {
Expand All @@ -22,6 +21,10 @@ connection.onInitialize((params) => {
};
});

connection.onDidChangeConfiguration(change => {
settings.eol = change.settings.files.eol;
});

const resolveParams = params => {
let doc = documents.get(params.textDocument.uri);
return {
Expand All @@ -33,33 +36,36 @@ const resolveParams = params => {
};

connection.onRequest({method: 'textDocument/formatting'}, (params) => {
let {textDocument, text} = resolveParams(params);
let {uri, textDocument, text} = resolveParams(params);

let range = Range.create(textDocument.positionAt(0), textDocument.positionAt(text.length));

try {
return [TextEdit.replace(range, format(workspaceRoot, text))];
return [TextEdit.replace(range, format(uri, text))];
} catch (e) {
connection.sendNotification({method: 'esformatter/formaterror'}, FORMAT_ERROR_MSG);
connection.sendNotification({
method: 'esformatter/formaterror'
}, FORMAT_ERROR_MSG);
return [];
}
});

connection.onRequest({method: 'textDocument/rangeFormatting'}, (params) => {
let range = params.range;
let {text} = resolveParams(params);
let {uri, text} = resolveParams(params);

let textLines = text.split(settings.eol);
let selectedText = textLines.slice(range.start.line, range.end.line + 1).join(settings.eol);

try {
let formatedText = format(workspaceRoot, selectedText);

let formatedText = format(uri, selectedText);
let newRange = Range.create(Position.create(range.start.line, 0), Position.create(range.end.line, textLines[range.end.line].length));

return [TextEdit.replace(newRange, formatedText)];
} catch (e) {
connection.sendNotification({method: 'esformatter/formaterror'}, SELECTED_FORMAT_ERROR_MSG);
connection.sendNotification({
method: 'esformatter/formaterror'
}, SELECTED_FORMAT_ERROR_MSG);
return [];
}
});
Expand Down

0 comments on commit 349f0ce

Please sign in to comment.