@@ -524,8 +524,12 @@ namespace FourSlashInterface {
524
524
/**
525
525
* This method *requires* an ordered stream of classifications for a file, and spans are highly recommended.
526
526
*/
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 ) ;
529
533
}
530
534
531
535
public renameInfoSucceeded ( displayName ?: string , fullDisplayName ?: string , kind ?: string , kindModifiers ?: string , fileToRename ?: string , expectedRange ?: FourSlash . Range , options ?: ts . RenameInfoOptions ) {
@@ -768,109 +772,163 @@ namespace FourSlashInterface {
768
772
}
769
773
}
770
774
771
- interface Classification {
775
+ interface OlderClassification {
772
776
classificationType : ts . ClassificationTypeNames ;
773
777
text : string ;
774
778
textSpan ?: FourSlash . TextSpan ;
775
779
}
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 {
778
808
return getClassification ( ts . ClassificationTypeNames . comment , text , position ) ;
779
809
}
780
810
781
- export function identifier ( text : string , position ?: number ) : Classification {
811
+ function identifier ( text : string , position ?: number ) : Classification {
782
812
return getClassification ( ts . ClassificationTypeNames . identifier , text , position ) ;
783
813
}
784
814
785
- export function keyword ( text : string , position ?: number ) : Classification {
815
+ function keyword ( text : string , position ?: number ) : Classification {
786
816
return getClassification ( ts . ClassificationTypeNames . keyword , text , position ) ;
787
817
}
788
818
789
- export function numericLiteral ( text : string , position ?: number ) : Classification {
819
+ function numericLiteral ( text : string , position ?: number ) : Classification {
790
820
return getClassification ( ts . ClassificationTypeNames . numericLiteral , text , position ) ;
791
821
}
792
822
793
- export function operator ( text : string , position ?: number ) : Classification {
823
+ function operator ( text : string , position ?: number ) : Classification {
794
824
return getClassification ( ts . ClassificationTypeNames . operator , text , position ) ;
795
825
}
796
826
797
- export function stringLiteral ( text : string , position ?: number ) : Classification {
827
+ function stringLiteral ( text : string , position ?: number ) : Classification {
798
828
return getClassification ( ts . ClassificationTypeNames . stringLiteral , text , position ) ;
799
829
}
800
830
801
- export function whiteSpace ( text : string , position ?: number ) : Classification {
831
+ function whiteSpace ( text : string , position ?: number ) : Classification {
802
832
return getClassification ( ts . ClassificationTypeNames . whiteSpace , text , position ) ;
803
833
}
804
834
805
- export function text ( text : string , position ?: number ) : Classification {
835
+ function text ( text : string , position ?: number ) : Classification {
806
836
return getClassification ( ts . ClassificationTypeNames . text , text , position ) ;
807
837
}
808
838
809
- export function punctuation ( text : string , position ?: number ) : Classification {
839
+ function punctuation ( text : string , position ?: number ) : Classification {
810
840
return getClassification ( ts . ClassificationTypeNames . punctuation , text , position ) ;
811
841
}
812
842
813
- export function docCommentTagName ( text : string , position ?: number ) : Classification {
843
+ function docCommentTagName ( text : string , position ?: number ) : Classification {
814
844
return getClassification ( ts . ClassificationTypeNames . docCommentTagName , text , position ) ;
815
845
}
816
846
817
- export function className ( text : string , position ?: number ) : Classification {
847
+ function className ( text : string , position ?: number ) : Classification {
818
848
return getClassification ( ts . ClassificationTypeNames . className , text , position ) ;
819
849
}
820
850
821
- export function enumName ( text : string , position ?: number ) : Classification {
851
+ function enumName ( text : string , position ?: number ) : Classification {
822
852
return getClassification ( ts . ClassificationTypeNames . enumName , text , position ) ;
823
853
}
824
854
825
- export function interfaceName ( text : string , position ?: number ) : Classification {
855
+ function interfaceName ( text : string , position ?: number ) : Classification {
826
856
return getClassification ( ts . ClassificationTypeNames . interfaceName , text , position ) ;
827
857
}
828
858
829
- export function moduleName ( text : string , position ?: number ) : Classification {
859
+ function moduleName ( text : string , position ?: number ) : Classification {
830
860
return getClassification ( ts . ClassificationTypeNames . moduleName , text , position ) ;
831
861
}
832
862
833
- export function typeParameterName ( text : string , position ?: number ) : Classification {
863
+ function typeParameterName ( text : string , position ?: number ) : Classification {
834
864
return getClassification ( ts . ClassificationTypeNames . typeParameterName , text , position ) ;
835
865
}
836
866
837
- export function parameterName ( text : string , position ?: number ) : Classification {
867
+ function parameterName ( text : string , position ?: number ) : Classification {
838
868
return getClassification ( ts . ClassificationTypeNames . parameterName , text , position ) ;
839
869
}
840
870
841
- export function typeAliasName ( text : string , position ?: number ) : Classification {
871
+ function typeAliasName ( text : string , position ?: number ) : Classification {
842
872
return getClassification ( ts . ClassificationTypeNames . typeAliasName , text , position ) ;
843
873
}
844
874
845
- export function jsxOpenTagName ( text : string , position ?: number ) : Classification {
875
+ function jsxOpenTagName ( text : string , position ?: number ) : Classification {
846
876
return getClassification ( ts . ClassificationTypeNames . jsxOpenTagName , text , position ) ;
847
877
}
848
878
849
- export function jsxCloseTagName ( text : string , position ?: number ) : Classification {
879
+ function jsxCloseTagName ( text : string , position ?: number ) : Classification {
850
880
return getClassification ( ts . ClassificationTypeNames . jsxCloseTagName , text , position ) ;
851
881
}
852
882
853
- export function jsxSelfClosingTagName ( text : string , position ?: number ) : Classification {
883
+ function jsxSelfClosingTagName ( text : string , position ?: number ) : Classification {
854
884
return getClassification ( ts . ClassificationTypeNames . jsxSelfClosingTagName , text , position ) ;
855
885
}
856
886
857
- export function jsxAttribute ( text : string , position ?: number ) : Classification {
887
+ function jsxAttribute ( text : string , position ?: number ) : Classification {
858
888
return getClassification ( ts . ClassificationTypeNames . jsxAttribute , text , position ) ;
859
889
}
860
890
861
- export function jsxText ( text : string , position ?: number ) : Classification {
891
+ function jsxText ( text : string , position ?: number ) : Classification {
862
892
return getClassification ( ts . ClassificationTypeNames . jsxText , text , position ) ;
863
893
}
864
894
865
- export function jsxAttributeStringLiteralValue ( text : string , position ?: number ) : Classification {
895
+ function jsxAttributeStringLiteralValue ( text : string , position ?: number ) : Classification {
866
896
return getClassification ( ts . ClassificationTypeNames . jsxAttributeStringLiteralValue , text , position ) ;
867
897
}
868
898
869
899
function getClassification ( classificationType : ts . ClassificationTypeNames , text : string , position ?: number ) : Classification {
870
900
const textSpan = position === undefined ? undefined : { start : position , end : position + text . length } ;
871
901
return { classificationType, text, textSpan } ;
872
902
}
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
+ } ;
873
930
}
931
+
874
932
export namespace Completion {
875
933
export import SortText = ts . Completions . SortText ;
876
934
export import CompletionSource = ts . Completions . CompletionSource ;
0 commit comments