@@ -524,8 +524,12 @@ namespace FourSlashInterface {
524524 /**
525525 * This method *requires* an ordered stream of classifications for a file, and spans are highly recommended.
526526 */
527- public semanticClassificationsAre ( ...classifications : Classification [ ] ) {
528- this . state . verifySemanticClassifications ( classifications ) ;
527+ public semanticClassificationsAre ( format : ts . SemanticClassificationFormat , ...classifications : Classification [ ] ) {
528+ this . state . verifySemanticClassifications ( format , classifications ) ;
529+ }
530+
531+ public replaceWithSemanticClassifications ( format : ts . SemanticClassificationFormat . TwentyTwenty ) {
532+ this . state . replaceWithSemanticClassifications ( format ) ;
529533 }
530534
531535 public renameInfoSucceeded ( displayName ?: string , fullDisplayName ?: string , kind ?: string , kindModifiers ?: string , fileToRename ?: string , expectedRange ?: FourSlash . Range , options ?: ts . RenameInfoOptions ) {
@@ -768,109 +772,163 @@ namespace FourSlashInterface {
768772 }
769773 }
770774
771- interface Classification {
775+ interface OlderClassification {
772776 classificationType : ts . ClassificationTypeNames ;
773777 text : string ;
774778 textSpan ?: FourSlash . TextSpan ;
775779 }
776- export namespace Classification {
777- export function comment ( text : string , position ?: number ) : Classification {
780+
781+ // The VS Code LSP
782+ interface ModernClassification {
783+ classificationType : string ;
784+ text ?: string ;
785+ textSpan ?: FourSlash . TextSpan ;
786+ }
787+
788+ type Classification = OlderClassification | ModernClassification ;
789+
790+ export function classification ( format : ts . SemanticClassificationFormat ) {
791+
792+ function semanticToken ( identifier : string , text : string , _position : number ) : Classification {
793+ return {
794+ classificationType : identifier ,
795+ text
796+ } ;
797+ }
798+
799+ if ( format === ts . SemanticClassificationFormat . TwentyTwenty ) {
800+ return {
801+ semanticToken
802+ } ;
803+ }
804+
805+ // Defaults to the previous semantic classifier factory functions
806+
807+ function comment ( text : string , position ?: number ) : Classification {
778808 return getClassification ( ts . ClassificationTypeNames . comment , text , position ) ;
779809 }
780810
781- export function identifier ( text : string , position ?: number ) : Classification {
811+ function identifier ( text : string , position ?: number ) : Classification {
782812 return getClassification ( ts . ClassificationTypeNames . identifier , text , position ) ;
783813 }
784814
785- export function keyword ( text : string , position ?: number ) : Classification {
815+ function keyword ( text : string , position ?: number ) : Classification {
786816 return getClassification ( ts . ClassificationTypeNames . keyword , text , position ) ;
787817 }
788818
789- export function numericLiteral ( text : string , position ?: number ) : Classification {
819+ function numericLiteral ( text : string , position ?: number ) : Classification {
790820 return getClassification ( ts . ClassificationTypeNames . numericLiteral , text , position ) ;
791821 }
792822
793- export function operator ( text : string , position ?: number ) : Classification {
823+ function operator ( text : string , position ?: number ) : Classification {
794824 return getClassification ( ts . ClassificationTypeNames . operator , text , position ) ;
795825 }
796826
797- export function stringLiteral ( text : string , position ?: number ) : Classification {
827+ function stringLiteral ( text : string , position ?: number ) : Classification {
798828 return getClassification ( ts . ClassificationTypeNames . stringLiteral , text , position ) ;
799829 }
800830
801- export function whiteSpace ( text : string , position ?: number ) : Classification {
831+ function whiteSpace ( text : string , position ?: number ) : Classification {
802832 return getClassification ( ts . ClassificationTypeNames . whiteSpace , text , position ) ;
803833 }
804834
805- export function text ( text : string , position ?: number ) : Classification {
835+ function text ( text : string , position ?: number ) : Classification {
806836 return getClassification ( ts . ClassificationTypeNames . text , text , position ) ;
807837 }
808838
809- export function punctuation ( text : string , position ?: number ) : Classification {
839+ function punctuation ( text : string , position ?: number ) : Classification {
810840 return getClassification ( ts . ClassificationTypeNames . punctuation , text , position ) ;
811841 }
812842
813- export function docCommentTagName ( text : string , position ?: number ) : Classification {
843+ function docCommentTagName ( text : string , position ?: number ) : Classification {
814844 return getClassification ( ts . ClassificationTypeNames . docCommentTagName , text , position ) ;
815845 }
816846
817- export function className ( text : string , position ?: number ) : Classification {
847+ function className ( text : string , position ?: number ) : Classification {
818848 return getClassification ( ts . ClassificationTypeNames . className , text , position ) ;
819849 }
820850
821- export function enumName ( text : string , position ?: number ) : Classification {
851+ function enumName ( text : string , position ?: number ) : Classification {
822852 return getClassification ( ts . ClassificationTypeNames . enumName , text , position ) ;
823853 }
824854
825- export function interfaceName ( text : string , position ?: number ) : Classification {
855+ function interfaceName ( text : string , position ?: number ) : Classification {
826856 return getClassification ( ts . ClassificationTypeNames . interfaceName , text , position ) ;
827857 }
828858
829- export function moduleName ( text : string , position ?: number ) : Classification {
859+ function moduleName ( text : string , position ?: number ) : Classification {
830860 return getClassification ( ts . ClassificationTypeNames . moduleName , text , position ) ;
831861 }
832862
833- export function typeParameterName ( text : string , position ?: number ) : Classification {
863+ function typeParameterName ( text : string , position ?: number ) : Classification {
834864 return getClassification ( ts . ClassificationTypeNames . typeParameterName , text , position ) ;
835865 }
836866
837- export function parameterName ( text : string , position ?: number ) : Classification {
867+ function parameterName ( text : string , position ?: number ) : Classification {
838868 return getClassification ( ts . ClassificationTypeNames . parameterName , text , position ) ;
839869 }
840870
841- export function typeAliasName ( text : string , position ?: number ) : Classification {
871+ function typeAliasName ( text : string , position ?: number ) : Classification {
842872 return getClassification ( ts . ClassificationTypeNames . typeAliasName , text , position ) ;
843873 }
844874
845- export function jsxOpenTagName ( text : string , position ?: number ) : Classification {
875+ function jsxOpenTagName ( text : string , position ?: number ) : Classification {
846876 return getClassification ( ts . ClassificationTypeNames . jsxOpenTagName , text , position ) ;
847877 }
848878
849- export function jsxCloseTagName ( text : string , position ?: number ) : Classification {
879+ function jsxCloseTagName ( text : string , position ?: number ) : Classification {
850880 return getClassification ( ts . ClassificationTypeNames . jsxCloseTagName , text , position ) ;
851881 }
852882
853- export function jsxSelfClosingTagName ( text : string , position ?: number ) : Classification {
883+ function jsxSelfClosingTagName ( text : string , position ?: number ) : Classification {
854884 return getClassification ( ts . ClassificationTypeNames . jsxSelfClosingTagName , text , position ) ;
855885 }
856886
857- export function jsxAttribute ( text : string , position ?: number ) : Classification {
887+ function jsxAttribute ( text : string , position ?: number ) : Classification {
858888 return getClassification ( ts . ClassificationTypeNames . jsxAttribute , text , position ) ;
859889 }
860890
861- export function jsxText ( text : string , position ?: number ) : Classification {
891+ function jsxText ( text : string , position ?: number ) : Classification {
862892 return getClassification ( ts . ClassificationTypeNames . jsxText , text , position ) ;
863893 }
864894
865- export function jsxAttributeStringLiteralValue ( text : string , position ?: number ) : Classification {
895+ function jsxAttributeStringLiteralValue ( text : string , position ?: number ) : Classification {
866896 return getClassification ( ts . ClassificationTypeNames . jsxAttributeStringLiteralValue , text , position ) ;
867897 }
868898
869899 function getClassification ( classificationType : ts . ClassificationTypeNames , text : string , position ?: number ) : Classification {
870900 const textSpan = position === undefined ? undefined : { start : position , end : position + text . length } ;
871901 return { classificationType, text, textSpan } ;
872902 }
903+
904+ return {
905+ comment,
906+ identifier,
907+ keyword,
908+ numericLiteral,
909+ operator,
910+ stringLiteral,
911+ whiteSpace,
912+ text,
913+ punctuation,
914+ docCommentTagName,
915+ className,
916+ enumName,
917+ interfaceName,
918+ moduleName,
919+ typeParameterName,
920+ parameterName,
921+ typeAliasName,
922+ jsxOpenTagName,
923+ jsxCloseTagName,
924+ jsxSelfClosingTagName,
925+ jsxAttribute,
926+ jsxText,
927+ jsxAttributeStringLiteralValue,
928+ getClassification
929+ } ;
873930 }
931+
874932 export namespace Completion {
875933 export import SortText = ts . Completions . SortText ;
876934 export import CompletionSource = ts . Completions . CompletionSource ;
0 commit comments