volar-service-emmet
Advanced tools
Comparing version 0.0.11 to 0.0.12
import type { Service } from '@volar/language-service'; | ||
declare const _default: () => Service; | ||
export default _default; | ||
export declare function create(): Service; | ||
export default create; |
121
out/index.js
@@ -26,66 +26,71 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.create = void 0; | ||
const emmet = __importStar(require("@vscode/emmet-helper")); | ||
const volar_service_html_1 = require("volar-service-html"); | ||
exports.default = () => (context) => { | ||
// https://docs.emmet.io/abbreviations/syntax/ | ||
const triggerCharacters = '>+^*()#.[]$@-{}'.split(''); | ||
if (!context) { | ||
return { triggerCharacters }; | ||
} | ||
return { | ||
triggerCharacters, | ||
isAdditionalCompletion: true, | ||
async provideCompletionItems(textDocument, position) { | ||
const syntax = emmet.getEmmetMode(textDocument.languageId === 'vue' ? 'html' : textDocument.languageId); | ||
if (!syntax) | ||
return; | ||
// fix https://github.com/vuejs/language-tools/issues/1329 | ||
if (syntax === 'html') { | ||
const htmlDocument = (0, volar_service_html_1.getHtmlDocument)(textDocument); | ||
const node = htmlDocument.findNodeAt(textDocument.offsetAt(position)); | ||
if (node.tag) { | ||
let insideBlock = false; | ||
if (node.startTagEnd !== undefined && node.endTagStart !== undefined) { | ||
insideBlock = textDocument.offsetAt(position) >= node.startTagEnd && textDocument.offsetAt(position) <= node.endTagStart; | ||
function create() { | ||
return (context) => { | ||
// https://docs.emmet.io/abbreviations/syntax/ | ||
const triggerCharacters = '>+^*()#.[]$@-{}'.split(''); | ||
if (!context) { | ||
return { triggerCharacters }; | ||
} | ||
return { | ||
triggerCharacters, | ||
isAdditionalCompletion: true, | ||
async provideCompletionItems(textDocument, position) { | ||
const syntax = emmet.getEmmetMode(textDocument.languageId === 'vue' ? 'html' : textDocument.languageId); | ||
if (!syntax) | ||
return; | ||
// fix https://github.com/vuejs/language-tools/issues/1329 | ||
if (syntax === 'html') { | ||
const htmlDocument = (0, volar_service_html_1.getHtmlDocument)(textDocument); | ||
const node = htmlDocument.findNodeAt(textDocument.offsetAt(position)); | ||
if (node.tag) { | ||
let insideBlock = false; | ||
if (node.startTagEnd !== undefined && node.endTagStart !== undefined) { | ||
insideBlock = textDocument.offsetAt(position) >= node.startTagEnd && textDocument.offsetAt(position) <= node.endTagStart; | ||
} | ||
if (!insideBlock) { | ||
return; | ||
} | ||
} | ||
if (!insideBlock) { | ||
return; | ||
} | ||
} | ||
// monkey fix https://github.com/johnsoncodehk/volar/issues/1105 | ||
if (syntax === 'jsx') | ||
return; | ||
const emmetConfig = await getEmmetConfig(syntax); | ||
return emmet.doComplete(textDocument, position, syntax, emmetConfig); | ||
}, | ||
}; | ||
async function getEmmetConfig(syntax) { | ||
const emmetConfig = await context?.env.getConfiguration?.('emmet') ?? {}; | ||
const syntaxProfiles = Object.assign({}, emmetConfig['syntaxProfiles'] || {}); | ||
const preferences = Object.assign({}, emmetConfig['preferences'] || {}); | ||
// jsx, xml and xsl syntaxes need to have self closing tags unless otherwise configured by user | ||
if (syntax === 'jsx' || syntax === 'xml' || syntax === 'xsl') { | ||
syntaxProfiles[syntax] = syntaxProfiles[syntax] || {}; | ||
if (typeof syntaxProfiles[syntax] === 'object' | ||
&& !syntaxProfiles[syntax].hasOwnProperty('self_closing_tag') // Old Emmet format | ||
&& !syntaxProfiles[syntax].hasOwnProperty('selfClosingStyle') // Emmet 2.0 format | ||
) { | ||
syntaxProfiles[syntax] = { | ||
...syntaxProfiles[syntax], | ||
selfClosingStyle: 'xml' | ||
}; | ||
} | ||
} | ||
// monkey fix https://github.com/johnsoncodehk/volar/issues/1105 | ||
if (syntax === 'jsx') | ||
return; | ||
const emmetConfig = await getEmmetConfig(syntax); | ||
return emmet.doComplete(textDocument, position, syntax, emmetConfig); | ||
}, | ||
return { | ||
preferences, | ||
showExpandedAbbreviation: emmetConfig['showExpandedAbbreviation'], | ||
showAbbreviationSuggestions: emmetConfig['showAbbreviationSuggestions'], | ||
syntaxProfiles, | ||
variables: emmetConfig['variables'], | ||
excludeLanguages: emmetConfig['excludeLanguages'], | ||
showSuggestionsAsSnippets: emmetConfig['showSuggestionsAsSnippets'] | ||
}; | ||
} | ||
}; | ||
async function getEmmetConfig(syntax) { | ||
const emmetConfig = await context?.env.getConfiguration?.('emmet') ?? {}; | ||
const syntaxProfiles = Object.assign({}, emmetConfig['syntaxProfiles'] || {}); | ||
const preferences = Object.assign({}, emmetConfig['preferences'] || {}); | ||
// jsx, xml and xsl syntaxes need to have self closing tags unless otherwise configured by user | ||
if (syntax === 'jsx' || syntax === 'xml' || syntax === 'xsl') { | ||
syntaxProfiles[syntax] = syntaxProfiles[syntax] || {}; | ||
if (typeof syntaxProfiles[syntax] === 'object' | ||
&& !syntaxProfiles[syntax].hasOwnProperty('self_closing_tag') // Old Emmet format | ||
&& !syntaxProfiles[syntax].hasOwnProperty('selfClosingStyle') // Emmet 2.0 format | ||
) { | ||
syntaxProfiles[syntax] = { | ||
...syntaxProfiles[syntax], | ||
selfClosingStyle: 'xml' | ||
}; | ||
} | ||
} | ||
return { | ||
preferences, | ||
showExpandedAbbreviation: emmetConfig['showExpandedAbbreviation'], | ||
showAbbreviationSuggestions: emmetConfig['showAbbreviationSuggestions'], | ||
syntaxProfiles, | ||
variables: emmetConfig['variables'], | ||
excludeLanguages: emmetConfig['excludeLanguages'], | ||
showSuggestionsAsSnippets: emmetConfig['showSuggestionsAsSnippets'] | ||
}; | ||
} | ||
}; | ||
} | ||
exports.create = create; | ||
exports.default = create; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "volar-service-emmet", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"main": "out/index.js", | ||
@@ -17,3 +17,3 @@ "license": "MIT", | ||
"@vscode/emmet-helper": "^2.8.6", | ||
"volar-service-html": "0.0.11" | ||
"volar-service-html": "0.0.12" | ||
}, | ||
@@ -31,3 +31,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "5be7c0c4fc41f4ebe3d8f3d272d3a0d8377973ad" | ||
"gitHead": "7422c8d99d498df660ff9be3491545a5b45b3622" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5684
104
+ Addedvolar-service-html@0.0.12(transitive)
- Removedvolar-service-html@0.0.11(transitive)
Updatedvolar-service-html@0.0.12