@@ -34,6 +34,7 @@ namespace ts.server {
3434 fileWatcher : FileWatcher ;
3535 formatCodeOptions = ts . clone ( CompilerService . defaultFormatCodeOptions ) ;
3636 path : Path ;
37+ scriptKind : ScriptKind ;
3738
3839 constructor ( private host : ServerHost , public fileName : string , public content : string , public isOpen = false ) {
3940 this . path = toPath ( fileName , host . getCurrentDirectory ( ) , createGetCanonicalFileName ( host . useCaseSensitiveFileNames ) ) ;
@@ -215,8 +216,16 @@ namespace ts.server {
215216 return this . roots . map ( root => root . fileName ) ;
216217 }
217218
218- getScriptKind ( ) {
219- return ScriptKind . Unknown ;
219+ getScriptKind ( fileName : string ) {
220+ const info = this . getScriptInfo ( fileName ) ;
221+ if ( ! info ) {
222+ return undefined ;
223+ }
224+
225+ if ( ! info . scriptKind ) {
226+ info . scriptKind = getScriptKindFromFileName ( fileName ) ;
227+ }
228+ return info . scriptKind ;
220229 }
221230
222231 getScriptVersion ( filename : string ) {
@@ -1013,7 +1022,7 @@ namespace ts.server {
10131022 * @param filename is absolute pathname
10141023 * @param fileContent is a known version of the file content that is more up to date than the one on disk
10151024 */
1016- openFile ( fileName : string , openedByClient : boolean , fileContent ?: string ) {
1025+ openFile ( fileName : string , openedByClient : boolean , fileContent ?: string , scriptKind ?: ScriptKind ) {
10171026 fileName = ts . normalizePath ( fileName ) ;
10181027 let info = ts . lookUp ( this . filenameToScriptInfo , fileName ) ;
10191028 if ( ! info ) {
@@ -1028,6 +1037,7 @@ namespace ts.server {
10281037 }
10291038 if ( content !== undefined ) {
10301039 info = new ScriptInfo ( this . host , fileName , content , openedByClient ) ;
1040+ info . scriptKind = scriptKind ;
10311041 info . setFormatOptions ( this . getFormatCodeOptions ( ) ) ;
10321042 this . filenameToScriptInfo [ fileName ] = info ;
10331043 if ( ! info . isOpen ) {
@@ -1077,9 +1087,9 @@ namespace ts.server {
10771087 * @param filename is absolute pathname
10781088 * @param fileContent is a known version of the file content that is more up to date than the one on disk
10791089 */
1080- openClientFile ( fileName : string , fileContent ?: string ) {
1090+ openClientFile ( fileName : string , fileContent ?: string , scriptKind ?: ScriptKind ) {
10811091 this . openOrUpdateConfiguredProjectForFile ( fileName ) ;
1082- const info = this . openFile ( fileName , /*openedByClient*/ true , fileContent ) ;
1092+ const info = this . openFile ( fileName , /*openedByClient*/ true , fileContent , scriptKind ) ;
10831093 this . addOpenFile ( info ) ;
10841094 this . printProjects ( ) ;
10851095 return info ;
0 commit comments