Description: Use tsserver from node-typescript package
Author: David Kalnischkies <donkult@debian.org>
Forwarded: not-needed

--- a/ycmd/completers/typescript/typescript_completer.py
+++ b/ycmd/completers/typescript/typescript_completer.py
@@ -38,10 +38,6 @@
 
 RESPONSE_TIMEOUT_SECONDS = 20
 
-TSSERVER_DIR = os.path.abspath(
-  os.path.join( os.path.dirname( __file__ ), '..', '..', '..', 'third_party',
-                'tsserver' ) )
-
 LOGFILE_FORMAT = 'tsserver_'
 
 
@@ -73,18 +69,12 @@
 
 
 def FindTSServer( user_options_path ):
-  tsserver = utils.FindExecutableWithFallback( user_options_path , None )
-  if tsserver and os.path.isfile( tsserver ):
-    return tsserver
-  # The TSServer executable is installed at the root directory on Windows while
-  # it's installed in the bin folder on other platforms.
-  for executable in [ os.path.join( TSSERVER_DIR,
-                                    'node_modules',
-                                    '.bin',
-                                    'tsserver' ),
-                      'tsserver' ]:
-    tsserver = utils.FindExecutable( executable )
-    if tsserver:
+  if user_options_path:
+      return utils.FindExecutableWithFallback( user_options_path , None )
+  if not os.path.exists( '/usr/share/nodejs/typescript/lib/tsserver.js' ):
+    return None
+  for tsserver in [ '/usr/lib/ycmd/tsserverwrapper', ]:
+    if os.path.exists( tsserver ):
       return tsserver
   return None
 
@@ -92,8 +82,7 @@
 def ShouldEnableTypeScriptCompleter( user_options ):
   tsserver = FindTSServer( user_options[ 'tsserver_binary_path' ] )
   if not tsserver:
-    LOGGER.error( 'Not using TypeScript completer: TSServer not installed '
-                  'in %s', TSSERVER_DIR )
+    LOGGER.error( 'Not using TypeScript completer as package node-typescript is not installed' )
     return False
   LOGGER.info( 'Using TypeScript completer with %s', tsserver )
   return True
@@ -282,10 +271,12 @@
     # At the time of writing, 'Content-Length' is the only supplied header.
     headers = {}
     while True:
-      headerline = self._tsserver_handle.stdout.readline().strip()
+      headerline = utils.ToUnicode(self._tsserver_handle.stdout.readline().strip())
       if not headerline:
         break
-      key, value = utils.ToUnicode( headerline ).split( ':', 1 )
+      if headerline.startswith('npm WARN npm'):
+        continue
+      key, value = headerline.split( ':', 1 )
       headers[ key.strip() ] = value.strip()
 
     # The response message is a JSON object which comes back on one line.
--- a/ycmd/tests/typescript/typescript_completer_test.py
+++ b/ycmd/tests/typescript/typescript_completer_test.py
@@ -24,6 +24,7 @@
     ShouldEnableTypeScriptCompleter,
     FindTSServer )
 from ycmd.tests.typescript import setUpModule, tearDownModule # noqa
+from ycmd.tests.test_utils import NotDebian
 
 
 class TypescriptCompleterTest( TestCase ):
@@ -32,6 +33,7 @@
     assert_that( ShouldEnableTypeScriptCompleter( user_options ) )
 
 
+  @NotDebian
   @patch( 'ycmd.utils.FindExecutable', return_value = None )
   def test_ShouldEnableTypeScriptCompleter_TsserverNotFound( self, *args ):
     user_options = user_options_store.GetAll()
--- a/ycmd/tests/javascriptreact/get_completions_test.py
+++ b/ycmd/tests/javascriptreact/get_completions_test.py
@@ -17,7 +17,7 @@
 
 import pprint
 import requests
-from hamcrest import assert_that, equal_to, has_entries, has_item
+from hamcrest import any_of, assert_that, equal_to, has_entries, has_item
 from ycmd.tests.javascriptreact import setUpModule, tearDownModule # noqa
 from ycmd.tests.javascriptreact import PathToTestFile, SharedYcmd
 from ycmd.tests.test_utils import CombineRequest
@@ -72,14 +72,21 @@
           'completions': has_item( has_entries( {
             'insertion_text':  'alinkColor',
             'extra_menu_info': '(property) Document.alinkColor: string',
-             'detailed_info':  '(property) Document.alinkColor: string\n'
+            'detailed_info':  any_of(equal_to(
+                               '(property) Document.alinkColor: string\n'
+                               '\n'
+                               'Sets or gets the color of all active links '
+                               'in the document.\n'
+                               '\n'
+                               'deprecated'), equal_to(
+                               '(property) Document.alinkColor: string\n'
                                '\n'
                                'Sets or gets the color of all active links '
                                'in the document.\n'
                                '\n'
                                'deprecated: [MDN Reference]'
                                '(https://developer.mozilla.org/docs/Web/'
-                               'API/Document/alinkColor)',
+                               'API/Document/alinkColor)')),
             'kind':            'property',
           } ) )
         } )
