没有明显的原因,周一,我的VS2017开始在这篇SO帖子中突出显示错误,所有JS智能感知和自动格式化都消失了。
设法通过关闭Enable the new JavaScript language service
来修复它,但现在自动格式化忽略了我的设置; 内部样式是在函数之后的换行符上大括号,这是设置的,但 Ctrl-E-D 重新格式化现在将所有大括号移动到与函数定义相同的行。
我该如何解决这个问题?
编辑:我发现这个旧线程具有相同的问题,但遗憾的是没有修复新的语言服务:https://developercommunity.visualstudio.com/content/problem/138728/if-statements-still-place-a-opening-brace-on-the-s.html
令人恼火的是,它已经工作了几个月,昨天才停止,没有更改设置。
编辑以添加智能感知错误:
The JavaScript and TypeScript language service has been disabled due to an error. You may see reduced IntelliSense support for your project. Please try reloading your solution to reenable the language service.
Error processing request. Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
at createSourceFile (C:Program Files (x86)Microsoft SDKsTypeScript3.1tsserver.js:16674:110)
at Object.parseJsonText (C:Program Files (x86)Microsoft SDKsTypeScript3.1tsserver.js:16508:26)
at Object.parseJsonText (C:Program Files (x86)Microsoft SDKsTypeScript3.1tsserver.js:16330:23)
at ProjectService.loadConfiguredProject (C:Program Files (x86)Microsoft SDKsTypeScript3.1tsserver.js:120258:33)
at ProjectService.createAndLoadConfiguredProject (C:Program Files (x86)Microsoft SDKsTypeScript3.1tsserver.js:120247:22)
at ProjectService.createLoadAndUpdateConfiguredProject (C:Program Files (x86)Microsoft SDKsTypeScript3.1tsserver.js:120251:36)
at ProjectService.openClientFileWithNormalizedPath (C:Program Files (x86)Microsoft SDKsTypeScript3.1tsserver.js:120776:44)
at ProjectService.applyChangesInOpenFiles (C:Program Files (x86)Microsoft SDKsTypeScript3.1tsserver.js:120882:30)
at Session.handlers.ts.createMapFromTemplate._a.(anonymous function) (C:Program Files (x86)Microsoft SDKsTypeScript3.1tsserver.js:121548:46)
at C:Program Files (x86)Microsoft SDKsTypeScript3.1tsserver.js:123063:88
at IOSession.Session.executeWithRequestId (C:Program Files (x86)Microsoft SDKsTypeScript3.1tsserver.js:123054:28)
at IOSession.Session.executeCommand (C:Program Files (x86)Microsoft SDKsTypeScript3.1tsserver.js:123063:33)
at IOSession.Session.onMessage (C:Program Files (x86)Microsoft SDKsTypeScript3.1tsserver.js:123083:35)
at Interface.<anonymous> (C:Program Files (x86)Microsoft SDKsTypeScript3.1tsserver.js:124346:27)
at Interface.emit (events.js:182:13)
at Interface._onLine (readline.js:290:10)
at Interface._normalWrite (readline.js:433:12)
at Socket.ondata (readline.js:149:10)
at Socket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
at Socket.Readable.push (_stream_readable.js:219:10)
at Pipe.onread (net.js:638:20)
禁用新的语言服务。
1.禁用JavaScript Language Service
后,在开发人员命令提示符下使用以下命令设置选项:
CD %VSINSTALLDIR%
vsregedit set . HKCU "ApplicationPrivateSettingsTextEditorJavaScriptSpecific" "PlaceOpenBraceOnNewLineForControlBlocks" string "0*System.Int32*1"
看到这里。
启用新的语言服务。
2.尝试创建一个新项目(也许您在节点.js项目中?(以检查类似的问题是否仍然存在,如果此问题消失,则可能是问题的原因现在您的项目包含太多JS文件。请参阅此处的限制。
如果问题在新项目中仍然存在,请修复VS或将VS2017更新到最新的15.9.16以检查是否有帮助。我想你的环境中有什么东西坏了。
此外,尝试在关闭 VS 后删除解决方案目录中隐藏的.vs
文件夹,清理 VS 缓存并重新启动 VS。