2017-05-29 76 views
8

我在Visual Studio代碼中運行一個可以執行我的JS文件(使用duktape)的外部二進制文件的調試設置。調試適配器當前僅支持附加請求(不啓動),所以我必須在調試JS腳本之前運行二進制文件。如何讓vscode不等待完成preLaunchTask?

爲了避免啓動應用程序手動我創建了一個任務,並設置在我launch.json文件:

{ 
    "version": "0.2.0", 
    "configurations": [{ 
     "name": "Attach MGA", 
     "type": "duk", 
     "preLaunchTask": "debug mga", 
     "request": "attach", 

     "address": "localhost", 
     "port": 9091, 

     "localRoot": "${workspaceRoot}", 

     "stopOnEntry": false, 
     "debugLog": true 
    }] 
} 

的任務是定義這樣:

{ 
    "version": "0.1.0", 
    "command": "<absolute path to>/mga", 
    "isShellCommand": false, 
    "showOutput": "always", 
    "suppressTaskName": true, 
    "tasks": [{ 
     "taskName": "debug mga", 
     "args": ["--debugger", "main.json"] 
    }] 
} 

現在的問題是,當應用程序等待調試器連接時,vscode會等待預啓動任務完成。 Catch 22.

如何避免vscode等待預啓動任務完成?

更新

同時我已經the vscode task page念起來完成這個任務的配置上來。不過,它不適合我

{ 
    "version": "2.0.0", 
    "tasks": [ 
     { 
      "label": "launch-mga", 
      "type": "shell", 
      "command": "<absolute path to>/mga", 
      "args": [ 
       "config/main.json", 
       "--debugger" 
      ], 
      "isBackground": true, 
      "problemMatcher": { 
       "owner": "custom", 
       "pattern": { 
        "regexp": "_____" 
       }, 
       "background": { 
        "activeOnStart": true, 
        "beginsPattern": "^.*Waiting for debug connection.*$", 
        "endsPattern": "^.*blah.*$" 
       }, 
      }, 
     } 
    ] 
} 

啓動的應用程序打印工作等待消息,然後等待無休止的調試連接。也許這個問題與用C++編寫的應用程序(這有點類似於終端應用程序的Node.js)有關?

回答

0

如何試圖通過增加使其後臺作業: "isBackground": true

+0

這沒有幫助。 vscode仍在等待預啓動任務完成。 –

3

背景/看任務

有些工具在後臺支持運行一邊看文件系統的更改,然後觸發動作當文件在磁盤上更改時。通過Gulp這樣的功能通過npm模塊gulp-watch提供。 TypeScript編譯器tsc通過--watch command行選項內置了對此的支持。

爲了提供在VS代碼中激活後臺任務並生成問題結果的反饋,問題匹配器必須使用附加信息來檢測輸出中的這些變化。我們以tsc編譯器爲例。當編譯器在觀看模式啓動,它打印到控制檯以下附加信息:

> tsc --watch 
12:30:36 PM - Compilation complete. Watching for file changes. 

當它包含一個問題磁盤上的文件的變化,會出現以下的輸出:

12:32:35 PM - File change detected. Starting incremental compilation... 
src/messages.ts(276,9): error TS2304: Cannot find name 'candidate'. 
12:32:35 PM - Compilation complete. Watching for file changes. 

展望在輸出處顯示以下模式:

  • 編譯器在File change detected. Starting incremental compilation...打印到控制檯時運行。
  • 編譯器在Compilation complete. Watching for file changes.打印到控制檯時停止。
  • 在這兩個字符串之間會報告問題。
  • 編譯器也在初始啓動時運行一次(不向控制檯打印File change detected. Starting incremental compilation...)。

要捕獲此信息,問題匹配器可以提供background屬性。

對於tsc編譯器,一個合適的background屬性看起來是這樣的:

"background": { 
    "activeOnStart": true, 
    "beginsPattern": "^\\s*\\d{1,2}:\\d{1,2}:\\d{1,2}(?: AM| PM)? - File change detected\\. Starting incremental compilation\\.\\.\\.", 
    "endsPattern": "^\\s*\\d{1,2}:\\d{1,2}:\\d{1,2}(?: AM| PM)? - Compilation complete\\. Watching for file changes\\." 
} 

除了對問題匹配的background性質,任務本身具有作爲isBackground以便任務繼續運行被標記在背景中。

全手工製作的手錶模式下運行的tsc任務tasks.json看起來是這樣的:

{ 
    "version": "2.0.0", 
    "tasks": [ 
     { 
      "label": "watch", 
      "command": "tsc", 
      "args": ["--watch"], 
      "isBackground": true, 
      "problemMatcher": { 
       "owner": "typescript", 
       "fileLocation": "relative", 
       "pattern": { 
        "regexp": "^([^\\s].*)\\((\\d+|\\,\\d+|\\d+,\\d+,\\d+,\\d+)\\):\\s+(error|warning|info)\\s+(TS\\d+)\\s*:\\s*(.*)$", 
        "file": 1, 
        "location": 2, 
        "severity": 3, 
        "code": 4, 
        "message": 5 
       }, 
       "background": { 
        "activeOnStart": true, 
        "beginsPattern": "^\\s*\\d{1,2}:\\d{1,2}:\\d{1,2}(?: AM| PM)? - File change detected\\. Starting incremental compilation\\.\\.\\.", 
        "endsPattern": "^\\s*\\d{1,2}:\\d{1,2}:\\d{1,2}(?: AM| PM)? - Compilation complete\\. Watching for file changes\\." 
       } 
      } 
     } 
    ] 
} 

PS:從https://code.visualstudio.com/docs/editor/tasks採取內容

編輯-1

的任務需要作爲守護進程啓動,然後只有isBackground會幫助。所以你會有類似的東西

"isShellCommand": true, 
"command": "<absolute path to>/mga --config xyz abc &", 
+0

不幸的是,'isBackground'沒有幫助。 vscode仍在等待預啓動任務完成。 –

+0

@MikeLischke,請檢查編輯,看看它是否有幫助 –

+0

Stil沒有運氣。在更改爲您在編輯中推薦的內容後,我只會收到錯誤消息:'無法啓動外部程序<絕對路徑>/mga --debugger config/main.json&。 spawn <絕對路徑>/mga --debugger config/main.json&ENOENT'。很奇怪。 –