Skip to content

Commit

Permalink
feat: allow globalconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
joeveiga committed Jun 26, 2022
1 parent fa61c67 commit f1b1bc9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ lspconfig.emmet_ls.setup({
capabilities = capabilities,
filetypes = { 'html', 'typescriptreact', 'javascriptreact', 'css', 'sass', 'scss', 'less' },
init_options = {
-- For possible options, see: https://github.com/emmetio/emmet/blob/master/src/config.ts#L79-L267
["bem.enabled"] = true
html = {
options = {
-- For possible options, see: https://github.com/emmetio/emmet/blob/master/src/config.ts#L79-L267
["bem.enabled"] = true,
},
},
}
})
```
Expand Down
21 changes: 8 additions & 13 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import {
extract,
GlobalConfig,
parseMarkup,
parseStylesheet,
resolveConfig,
stringifyMarkup,
stringifyStylesheet,
Options
} from "emmet";
import { TextDocument } from "vscode-languageserver-textdocument";
import {
Expand All @@ -31,12 +31,7 @@ const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);

let hasConfigurationCapability: boolean = false;
let hasWorkspaceFolderCapability: boolean = false;

type EmmetOptions = Partial<Options>;
const defaultEmmetOptions: EmmetOptions = {
"output.field": (index, placeholder) => `\$\{${index}${placeholder ? ":" + placeholder : ""}\}`
};
let emmetOptions: EmmetOptions = defaultEmmetOptions;
let globalConfig: GlobalConfig = {};

connection.onInitialize((params: InitializeParams) => {
const capabilities = params.capabilities;
Expand All @@ -50,10 +45,7 @@ connection.onInitialize((params: InitializeParams) => {
capabilities.workspace && !!capabilities.workspace.workspaceFolders
);

emmetOptions = {
...defaultEmmetOptions,
...(params.initializationOptions || {})
};
globalConfig = params.initializationOptions || {};

const triggerCharacters = [
">",
Expand Down Expand Up @@ -192,8 +184,11 @@ connection.onCompletion(
const emmetConfig = resolveConfig({
syntax,
type,
options: emmetOptions
});
options: {
"output.field": (index, placeholder) =>
`\$\{${index}${placeholder ? ":" + placeholder : ""}\}`,
},
}, globalConfig);

let textResult = "";
if (!isStylesheet) {
Expand Down

0 comments on commit f1b1bc9

Please sign in to comment.