@@ -50,6 +50,68 @@ namespace ts.projectSystem {
5050 } ) ;
5151 } ) ;
5252
53+ it ( "load global plugins" , ( ) => {
54+ const f1 = {
55+ path : "/a/file1.ts" ,
56+ content : "let x = [1, 2];"
57+ } ;
58+ const p1 = { projectFileName : "/a/proj1.csproj" , rootFiles : [ toExternalFile ( f1 . path ) ] , options : { } } ;
59+
60+ const host = createServerHost ( [ f1 ] ) ;
61+ host . require = ( _initialPath , moduleName ) => {
62+ assert . equal ( moduleName , "myplugin" ) ;
63+ return {
64+ module : ( ) => ( {
65+ create ( info : server . PluginCreateInfo ) {
66+ const proxy = Harness . LanguageService . makeDefaultProxy ( info ) ;
67+ proxy . getSemanticDiagnostics = filename => {
68+ const prev = info . languageService . getSemanticDiagnostics ( filename ) ;
69+ const sourceFile : SourceFile = info . project . getSourceFile ( toPath ( filename , /*basePath*/ undefined , createGetCanonicalFileName ( info . serverHost . useCaseSensitiveFileNames ) ) ) ! ;
70+ prev . push ( {
71+ category : DiagnosticCategory . Warning ,
72+ file : sourceFile ,
73+ code : 9999 ,
74+ length : 3 ,
75+ messageText : `Plugin diagnostic` ,
76+ start : 0
77+ } ) ;
78+ return prev ;
79+ } ;
80+ return proxy ;
81+ }
82+ } ) ,
83+ error : undefined
84+ } ;
85+ } ;
86+ const session = createSession ( host , { globalPlugins : [ "myplugin" ] } ) ;
87+
88+ session . executeCommand ( < protocol . OpenExternalProjectsRequest > {
89+ seq : 1 ,
90+ type : "request" ,
91+ command : "openExternalProjects" ,
92+ arguments : { projects : [ p1 ] }
93+ } ) ;
94+
95+ const projectService = session . getProjectService ( ) ;
96+ checkNumberOfProjects ( projectService , { externalProjects : 1 } ) ;
97+ assert . equal ( projectService . externalProjects [ 0 ] . getProjectName ( ) , p1 . projectFileName ) ;
98+
99+ const handlerResponse = session . executeCommand ( < protocol . SemanticDiagnosticsSyncRequest > {
100+ seq : 2 ,
101+ type : "request" ,
102+ command : "semanticDiagnosticsSync" ,
103+ arguments : {
104+ file : f1 . path ,
105+ projectFileName : p1 . projectFileName
106+ }
107+ } ) ;
108+
109+ assert . isDefined ( handlerResponse . response ) ;
110+ const response = handlerResponse . response as protocol . Diagnostic [ ] ;
111+ assert . equal ( response . length , 1 ) ;
112+ assert . equal ( response [ 0 ] . text , "Plugin diagnostic" ) ;
113+ } ) ;
114+
53115 it ( "remove not-listed external projects" , ( ) => {
54116 const f1 = {
55117 path : "/a/app.ts" ,
0 commit comments