import { valueMapping } from '@stylable/core' ; import type { ProviderRange } from './completion-providers' ; export class Completion { constructor ( public label , public detail = '' , public sortText = 'd' , public insertText = label , public range , public additionalCompletions = false , public triggerSignature = false ) { } } export class Snippet { constructor ( public source ) { } } export const importDirectives = { from : valueMapping . from , default : valueMapping . default , named : valueMapping . named , } ; export const rulesetDirectives = { extends : valueMapping . extends , mixin : valueMapping . mixin , states : valueMapping . states , } ; export const topLevelDirectives = { root : '.root' as const , namespace : '@namespace' as const , customSelector : '@custom-selector :--' as const , vars : ':vars' as const , import : ':import' as const , stScope : '@st-scope' as const , stImport : '@st-import' as const , stGlobalCustomProperty : '@st-global-custom-property' as const , } ; export function importInternalDirective ( type , rng ) { switch ( importDirectives [ type ] ) { case valueMapping . default : return new Completion ( valueMapping . default + ':' , 'Default export name' , 'a' , new Snippet ( valueMapping . default + ': $1;' ) , rng ) ; case valueMapping . from : return new Completion ( valueMapping . from + ':' , 'Path to library' , 'a' , new Snippet ( valueMapping . from + ': "$1";' ) , rng ) ; case valueMapping . named : return new Completion ( valueMapping . named + ':' , 'Named export name' , 'a' , new Snippet ( valueMapping . named + ': $1;' ) , rng ) ; } } export function rulesetInternalDirective ( type , rng ) { switch ( rulesetDirectives [ type ] ) { case valueMapping . extends : return new Completion ( valueMapping . extends + ':' , 'Extend an external component' , 'a' , new Snippet ( '-st-extends: $1;' ) , rng , true ) ; case valueMapping . mixin : return new Completion ( valueMapping . mixin + ':' , 'Apply mixins on the class' , 'a' , new Snippet ( '-st-mixin: $1;' ) , rng , true ) ; case valueMapping . states : return new Completion ( valueMapping . states + ':' , 'Define the CSS states available for this class' , 'a' , new Snippet ( '-st-states: $1;' ) , rng ) ; } } export function topLevelDirective ( type , rng ) { switch ( topLevelDirectives [ type ] ) { case topLevelDirectives . import : return new Completion ( topLevelDirectives . import , 'Import an external library' , 'a' , new Snippet ( ':import {\n\t-st-from: "$1";\n}' ) , rng ) ; case topLevelDirectives . namespace : return new Completion ( topLevelDirectives . namespace , 'Declare a namespace for the file' , 'a' , new Snippet ( '@namespace "$1";\n' ) , rng ) ; case topLevelDirectives . customSelector : return new Completion ( topLevelDirectives . customSelector . slice ( 0 , - 4 ) , 'Define a custom selector' , 'a' , topLevelDirectives . customSelector , rng ) ; case topLevelDirectives . root : return new Completion ( topLevelDirectives . root , 'The root class' , 'a' , undefined , rng ) ; case topLevelDirectives . vars : return new Completion ( topLevelDirectives . vars , 'Declare variables' , 'a' , new Snippet ( ':vars {\n\t$1\n}' ) , rng ) ; case topLevelDirectives . stScope : return new Completion ( topLevelDirectives . stScope , 'Define an @st-scope' , 'a' , new Snippet ( '@st-scope $1 {\n\t$2\n}' ) , rng ) ; case topLevelDirectives . stImport : return new Completion ( topLevelDirectives . stImport , 'Define an @st-import' , 'a' , new Snippet ( '@st-import $2 from "$1";' ) , rng ) ; case topLevelDirectives . stGlobalCustomProperty : return new Completion ( topLevelDirectives . stGlobalCustomProperty , 'Define global custom properties using @st-global-custom-property' , 'a' , new Snippet ( '@st-global-custom-property --$1;' ) , rng ) ; } } export function valueDirective ( rng ) { return new Completion ( 'value()' , 'Use the value of a variable' , 'a' , new Snippet ( ' value($1)' ) , rng ) ; } export function globalCompletion ( rng ) { return new Completion ( ':global()' , 'Target a global selector' , 'a' , new Snippet ( ':global($1)' ) , rng ) ; } export function classCompletion ( className , rng , removeDot = false ) { return new Completion ( ( removeDot ? '' : '.' ) + className , 'Stylable class or tag' , 'a' , undefined , rng ) ; } export function extendCompletion ( symbolName , from , rng ) { return new Completion ( symbolName , 'from: ' + from , 'a' , new Snippet ( symbolName ) , rng ) ; } export function namedCompletion ( symbolName , rng , from , value ? ) { return new Completion ( symbolName , 'from: ' + from + '\n' + 'Value: ' + value , 'a' , new Snippet ( symbolName ) , rng ) ; } export function cssMixinCompletion ( symbolName , rng , from ) { return new Completion ( symbolName , 'from: ' + from , 'a' , new Snippet ( symbolName ) , rng ) ; } export function codeMixinCompletion ( symbolName , rng , from ) { return new Completion ( symbolName , 'from: ' + from , 'a' , new Snippet ( symbolName + '($1)' ) , rng , false , true ) ; } export function formatterCompletion ( symbolName , rng , from ) { return new Completion ( symbolName , 'from: ' + from , 'a' , new Snippet ( symbolName + '($1)' ) , rng , false , true ) ; } export function pseudoElementCompletion ( elementName , from , rng ) { return new Completion ( '::' + elementName , 'from: ' + from , 'a' , '::' + elementName , rng ) ; } export function stateTypeCompletion ( type , from , rng ) { return new Completion ( `${ type }()` , `from: ${ from }` , 'a' , new Snippet ( `${ type }($1)` ) , rng , false ) ; } export function stateCompletion ( stateName , from , rng , type , hasParam ? ) { return new Completion ( ':' + stateName + ( hasParam ? '()' : '' ) , 'from: ' + from , 'a' , new Snippet ( ':' + stateName + ( hasParam ? '($1)' : '' ) ) , rng , type === 'enum' , hasParam ) ; } export function stateEnumCompletion ( option , from , rng ) { return new Completion ( option , 'from: ' + from , 'a' , new Snippet ( option ) , rng , false ) ; } export function valueCompletion ( name , from , value , rng ) { return new Completion ( name , 'from: ' + from + '\n' + 'value: ' + value , 'a' , new Snippet ( name ) , rng ) ; }