Skip to content

Commit

Permalink
Merge pull request #116 from redhat-developer/use_lsp_tab_size
Browse files Browse the repository at this point in the history
Use tabWidth setting from editor when formatting
  • Loading branch information
JPinkney authored Feb 2, 2019
2 parents 9ac45dc + 8c54e34 commit 1458e25
Showing 1 changed file with 7 additions and 24 deletions.
31 changes: 7 additions & 24 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,14 @@ connection.onInitialize((params: InitializeParams): InitializeResult => {
workspaceFolders = params["workspaceFolders"];
workspaceRoot = URI.parse(params.rootPath);

function hasClientCapability(...keys: string[]) {
let c = params.capabilities;
for (let i = 0; c && i < keys.length; i++) {
c = c[keys[i]];
}
return !!c;
}

hasWorkspaceFolderCapability = capabilities.workspace && !!capabilities.workspace.workspaceFolders;
clientDynamicRegisterSupport = hasClientCapability('textDocument', 'formatting', 'dynamicRegistration');
return {
capabilities: {
textDocumentSync: documents.syncKind,
completionProvider: { resolveProvider: true },
hoverProvider: true,
documentSymbolProvider: true,
documentFormattingProvider: false
documentFormattingProvider: true
}
};
});
Expand Down Expand Up @@ -248,19 +239,6 @@ connection.onDidChangeConfiguration((change) => {
setSchemaStoreSettingsIfNotSet();

updateConfiguration();

// dynamically enable & disable the formatter
if (clientDynamicRegisterSupport) {
let enableFormatter = settings && settings.yaml && settings.yaml.format && settings.yaml.format.enable;
if (enableFormatter) {
if (!formatterRegistration) {
formatterRegistration = connection.client.register(DocumentFormattingRequest.type, { documentSelector: [{ language: 'yaml' }] });
}
} else if (formatterRegistration) {
formatterRegistration.then(r => r.dispose());
formatterRegistration = null;
}
}
});

function setSchemaStoreSettingsIfNotSet(){
Expand Down Expand Up @@ -587,7 +565,12 @@ connection.onDocumentFormatting(formatParams => {
return;
}

return customLanguageService.doFormat(document, yamlFormatterSettings);
const customFormatterSettings = {
tabWidth: formatParams.options.tabSize,
...yamlFormatterSettings
}

return customLanguageService.doFormat(document, customFormatterSettings);
});

connection.listen();

0 comments on commit 1458e25

Please sign in to comment.