volar-service-emmet
Advanced tools
Comparing version 0.0.17 to 0.0.18
@@ -1,4 +0,3 @@ | ||
import type { Service } from '@volar/language-service'; | ||
export declare function create(): Service; | ||
export default create; | ||
import type { ServicePlugin } from '@volar/language-service'; | ||
export declare function create(): ServicePlugin; | ||
//# sourceMappingURL=empty.d.ts.map |
@@ -6,6 +6,9 @@ "use strict"; | ||
function create() { | ||
return () => ({}); | ||
return { | ||
create() { | ||
return {}; | ||
}, | ||
}; | ||
} | ||
exports.create = create; | ||
exports.default = create; | ||
//# sourceMappingURL=empty.js.map |
@@ -1,4 +0,3 @@ | ||
import type { Service } from '@volar/language-service'; | ||
export declare function create(): Service; | ||
export default create; | ||
import type { ServicePlugin } from '@volar/language-service'; | ||
export declare function create(): ServicePlugin; | ||
//# sourceMappingURL=index.d.ts.map |
113
out/index.js
@@ -6,68 +6,65 @@ "use strict"; | ||
const volar_service_html_1 = require("volar-service-html"); | ||
// https://docs.emmet.io/abbreviations/syntax/ | ||
const triggerCharacters = '>+^*()#.[]$@-{}'.split(''); | ||
function create() { | ||
return (context) => { | ||
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; | ||
return { | ||
// https://docs.emmet.io/abbreviations/syntax/ | ||
triggerCharacters: '>+^*()#.[]$@-{}'.split(''), | ||
create(context) { | ||
return { | ||
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); | ||
}, | ||
}; | ||
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'] | ||
}; | ||
} | ||
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.17", | ||
"version": "0.0.18", | ||
"description": "Integrate @vscode/emmet-helper into Volar", | ||
@@ -29,6 +29,6 @@ "homepage": "https://github.com/volarjs/services/tree/master/packages/emmet", | ||
"@vscode/emmet-helper": "^2.9.2", | ||
"volar-service-html": "0.0.17" | ||
"volar-service-html": "0.0.18" | ||
}, | ||
"peerDependencies": { | ||
"@volar/language-service": "~1.11.0" | ||
"@volar/language-service": "2.0.0-alpha.0" | ||
}, | ||
@@ -43,3 +43,3 @@ "peerDependenciesMeta": { | ||
}, | ||
"gitHead": "bf42bae9b399b69125fd28c7a9bf95882c96068a" | ||
"gitHead": "8dedd3c6e73740fc7c1fe06df32b727ca504adc0" | ||
} |
6739
84
+ Added@volar/language-core@2.0.0-alpha.0(transitive)
+ Added@volar/language-service@2.0.0-alpha.0(transitive)
+ Added@volar/source-map@2.0.0-alpha.0(transitive)
+ Addedmuggle-string@0.4.1(transitive)
+ Addedvolar-service-html@0.0.18(transitive)
- Removed@volar/language-core@1.11.1(transitive)
- Removed@volar/language-service@1.11.1(transitive)
- Removed@volar/source-map@1.11.1(transitive)
- Removedmuggle-string@0.3.1(transitive)
- Removedvolar-service-html@0.0.17(transitive)
Updatedvolar-service-html@0.0.18