Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'vscode-languageserver-types' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
function collectCharacterEntityProposals(): CompletionList {
// character entities
let k = offset - 1
let characterStart = position.character
while (k >= 0 && isLetterOrDigit(text, k)) {
k--
characterStart--
}
if (k >= 0 && text[k] === '&') {
let range = Range.create(
Position.create(position.line, characterStart - 1),
position,
)
for (let entity in entities) {
if (endsWith(entity, ';')) {
const label = '&' + entity
result.items.push({
label,
kind: CompletionItemKind.Keyword,
documentation: `Character entity representing '${entities[entity]}'`,
textEdit: TextEdit.replace(range, label),
insertTextFormat: InsertTextFormat.PlainText,
})
}
}
}
if (isStyleSheet(syntax)) {
let { prefixOptions, abbreviationWithoutPrefix } = splitVendorPrefix(abbreviation);
// If abbreviation is valid, then expand it and ensure the expanded value is not noise
if (isAbbreviationValid(syntax, abbreviation)) {
createExpandedAbbr(abbreviationWithoutPrefix);
}
// When abbr contains -, emmet uses it as a delimitor using the left to match propertyname and the right to match propertyvalue
// If there is css property that matches with abbr better, then that should win over emmet
if (abbreviationWithoutPrefix.indexOf('-') > 0 && cssData.properties.indexOf(abbreviationWithoutPrefix) > -1) {
return;
}
if (expandedAbbr) {
let prefixedExpandedText = applyVendorPrefixes(expandedText, prefixOptions, preferences);
expandedAbbr.textEdit = TextEdit.replace(abbreviationRange, escapeNonTabStopDollar(addFinalTabStop(prefixedExpandedText)));
expandedAbbr.documentation = replaceTabStopsWithCursors(prefixedExpandedText);
expandedAbbr.label = removeTabStops(expandedText);
expandedAbbr.filterText = abbreviation;
const stylesheetCustomSnippetsKeys = stylesheetCustomSnippetsKeyCache.has(syntax) ? stylesheetCustomSnippetsKeyCache.get(syntax) : stylesheetCustomSnippetsKeyCache.get('css');
completionItems = makeSnippetSuggestion(stylesheetCustomSnippetsKeys, abbreviation, abbreviation, abbreviationRange, expandOptions, 'Emmet Custom Snippet', false);
if (!completionItems.find(x => x.textEdit.newText === expandedAbbr.textEdit.newText)) {
// Fix for https://github.com/Microsoft/vscode/issues/28933#issuecomment-309236902
// When user types in propertyname, emmet uses it to match with snippet names, resulting in width -> widows or font-family -> font: family
// Filter out those cases here.
const abbrRegex = new RegExp('.*' + abbreviationWithoutPrefix.split('').map(x => x === '$' ? '\\$' : x).join('.*') + '.*', 'i');
if (/\d/.test(abbreviation) || abbrRegex.test(expandedAbbr.label)) {
completionItems.push(expandedAbbr);
}
import {DiagnosticSeverity} from 'vscode-languageserver-types';
import invariant from 'assert';
import nullthrows from 'nullthrows';
import URI from 'vscode-uri';
const FlowSeverity = {
Error: 'Error',
Warning: 'Warning',
};
const flowSeverityToLSPSeverityMap: {
[string]: DiagnosticSeverityType,
} = {
[FlowSeverity.Error]: DiagnosticSeverity.Error,
[FlowSeverity.Warning]: DiagnosticSeverity.Warning,
};
export function toURI(filePath: string): URI {
return URI.file(filePath);
}
export function hasFlowPragma(content: string) {
const hasPragma =
content.startsWith('/* @flow */') ||
content.startsWith('// @flow\n') ||
/^\s*\/\*+\s*@flow\s*\*+\//m.test(content) ||
/^\s*\/\/\s*@flow\s*$/m.test(content);
return hasPragma;
}
export function flowSeverityToLSPSeverity(
|| (!/^[a-z,A-Z,\d]*$/.test(abbreviation) && !abbreviation.endsWith('.'))
|| markupSnippetKeys.indexOf(abbreviation) > -1
|| commonlyUsedTags.indexOf(abbreviation) > -1) {
try {
expandedText = expand(abbreviation, expandOptions);
// Skip cases when abc -> abc: ; as this is noise
if (isStyleSheet(syntax) && expandedText === `${abbreviation}: \${1};`) {
expandedText = '';
}
} catch (e) {
}
}
if (expandedText) {
expandedAbbr = CompletionItem.create(abbreviation);
expandedAbbr.textEdit = TextEdit.replace(abbreviationRange, expandedText);
expandedAbbr.documentation = removeTabStops(expandedText);
expandedAbbr.insertTextFormat = InsertTextFormat.Snippet;
expandedAbbr.detail = 'Emmet Abbreviation';
if (filters.indexOf('bem') > -1) {
expandedAbbr.label = abbreviation + filterDelimitor + bemFilterSuffix;
}
if (isStyleSheet(syntax)) {
// See https://github.com/Microsoft/vscode/issues/28933#issuecomment-309236902
// Due to this we set filterText, sortText and label to expanded abbreviation
// - Label makes it clear to the user what their choice is
// - FilterText fixes the issue when user types in propertyname and emmet uses it to match with abbreviations
// - SortText will sort the choice in a way that is intutive to the user
expandedAbbr.filterText = expandedAbbr.documentation;
expandedAbbr.sortText = expandedAbbr.documentation;
expandedAbbr.label = expandedAbbr.documentation;
...change.textChanges.map(tc => {
// currently, only import codeAction is available
// change start of doc to start of script region
if (tc.span.start === 0 && tc.span.length === 0) {
const region = regionStart.get(doc);
if (region) {
const line = region.start.line;
return {
range: Range.create(line + 1, 0, line + 1, 0),
newText: tc.newText
};
}
}
return {
range: convertRange(doc, tc.span),
newText: tc.newText
};
})
);
languageFacts.cssDataManager.getProperties().forEach(function (p) {
var score = difference(propertyName, p.name);
if (score >= propertyName.length / 2 /*score_lim*/) {
candidates.push({ property: p.name, score: score });
}
});
// Sort in descending order.
candidates.sort(function (a, b) {
return b.score - a.score;
});
var maxActions = 3;
for (var _i = 0, candidates_1 = candidates; _i < candidates_1.length; _i++) {
var candidate = candidates_1[_i];
var propertyName_1 = candidate.property;
var title = localize('css.codeaction.rename', "Rename to '{0}'", propertyName_1);
var edit = TextEdit.replace(marker.range, propertyName_1);
var documentIdentifier = VersionedTextDocumentIdentifier.create(document.uri, document.version);
var workspaceEdit = { documentChanges: [TextDocumentEdit.create(documentIdentifier, [edit])] };
var codeAction = CodeAction.create(title, workspaceEdit, CodeActionKind.QuickFix);
codeAction.diagnostics = [marker];
result.push(codeAction);
if (--maxActions <= 0) {
return;
}
}
};
CSSCodeActions.prototype.appendFixesForMarker = function (document, stylesheet, marker, result) {
|| markupSnippetKeys.indexOf(abbreviation) > -1
|| commonlyUsedTags.indexOf(abbreviation) > -1) {
try {
expandedText = expand(abbreviation, expandOptions);
// Skip cases when abc -> abc: ; as this is noise
if (isStyleSheet(syntax) && expandedText === `${abbreviation}: \${1};`) {
expandedText = '';
}
} catch (e) {
}
}
if (expandedText) {
expandedAbbr = CompletionItem.create(abbreviation);
expandedAbbr.textEdit = TextEdit.replace(abbreviationRange, expandedText);
expandedAbbr.documentation = removeTabStops(expandedText);
expandedAbbr.insertTextFormat = InsertTextFormat.Snippet;
expandedAbbr.detail = 'Emmet Abbreviation';
if (filters.indexOf('bem') > -1) {
expandedAbbr.label = abbreviation + filterDelimitor + bemFilterSuffix;
}
if (isStyleSheet(syntax)) {
// See https://github.com/Microsoft/vscode/issues/28933#issuecomment-309236902
// Due to this we set filterText, sortText and label to expanded abbreviation
// - Label makes it clear to the user what their choice is
// - FilterText fixes the issue when user types in propertyname and emmet uses it to match with abbreviations
// - SortText will sort the choice in a way that is intutive to the user
expandedAbbr.filterText = expandedAbbr.documentation;
expandedAbbr.sortText = expandedAbbr.documentation;
expandedAbbr.label = expandedAbbr.documentation;
return CompletionList.create([expandedAbbr], true);
export function parseVueTemplate(text: string): string {
const doc = TextDocument.create('test://test/test.vue', 'vue', 0, text);
const regions = getVueDocumentRegions(doc);
const template = regions.getSingleTypeDocument('template');
if (template.languageId !== 'vue-html') {
return '';
}
const rawText = template.getText();
// skip checking on empty template
if (rawText.replace(/\s/g, '') === '') {
return '';
}
return rawText.replace(/ {10}/, '<template>') + '</template>';
}
CSSCompletion.prototype.getCompletionsForSelector = function (ruleSet, isNested, result) {
var _this = this;
var existingNode = this.findInNodePath(nodes.NodeType.PseudoSelector, nodes.NodeType.IdentifierSelector, nodes.NodeType.ClassSelector, nodes.NodeType.ElementNameSelector);
if (!existingNode && this.offset - this.currentWord.length > 0 && this.textDocument.getText()[this.offset - this.currentWord.length - 1] === ':') {
// after the ':' of a pseudo selector, no node generated for just ':'
this.currentWord = ':' + this.currentWord;
this.defaultReplaceRange = vscode_languageserver_types_1.Range.create(vscode_languageserver_types_1.Position.create(this.position.line, this.position.character - this.currentWord.length), this.position);
}
var pseudoClasses = languageFacts.cssDataManager.getPseudoClasses();
pseudoClasses.forEach(function (entry) {
var insertText = moveCursorInsideParenthesis(entry.name);
var item = {
label: entry.name,
textEdit: vscode_languageserver_types_1.TextEdit.replace(_this.getCompletionRange(existingNode), insertText),
documentation: languageFacts.getEntryDescription(entry),
kind: vscode_languageserver_types_1.CompletionItemKind.Function,
insertTextFormat: entry.name !== insertText ? SnippetFormat : void 0
};
if (strings.startsWith(entry.name, ':-')) {
item.sortText = 'x';
}
result.items.push(item);
});
.subscribe((newRange: types.Range) => {
const line0 = newRange.start.line
const line1 = newRange.end.line
const startLine = Math.min(line0, line1)
const endLine = Math.max(line0, line1)
// Clamp range to lines
const adjustedRange = types.Range.create(startLine, 0, endLine + 1, 0)
store.dispatch({
type: "SELECTION_CHANGED",
range: adjustedRange,
})
})