Skip to content

Commit

Permalink
partially fix #355, a crude watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
HerringtonDarkholme committed Feb 20, 2018
1 parent 7832af7 commit d342dff
Show file tree
Hide file tree
Showing 4 changed files with 608 additions and 10 deletions.
2 changes: 2 additions & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
},
"homepage": "https://github.com/vuejs/vetur/tree/master/server",
"dependencies": {
"@types/chokidar": "^1.7.4",
"bootstrap-vue-helper-json": "^1.1.1",
"chokidar": "^2.0.2",
"element-helper-json": "^2.0.2",
"eslint": "^4.13.1",
"eslint-plugin-vue": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion server/src/modes/script/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ export function getJavascriptMode(
jsDocuments.onDocumentRemoved(document);
},
dispose() {
serviceHost.getService().dispose();
serviceHost.dispose();
jsDocuments.dispose();
}
};
Expand Down
18 changes: 17 additions & 1 deletion server/src/modes/script/serviceHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { LanguageModelCache } from '../languageModelCache';
import { createUpdater, parseVue, isVue } from './preprocess';
import { getFileFsPath, getFilePath } from '../../utils/paths';
import * as bridge from './bridge';
import * as chokidar from 'chokidar';

// Patch typescript functions to insert `import Vue from 'vue'` and `new Vue` around export default.
// NOTE: this is a global hack that all ts instances after is changed
Expand Down Expand Up @@ -68,6 +69,18 @@ export function getServiceHost(workspacePath: string, jsDocuments: LanguageModel
...parsedConfig.options
};
compilerOptions.allowNonTsExtensions = true;
const watcher = chokidar.watch(workspacePath, {
ignoreInitial: true,
ignored: defaultIgnorePatterns(workspacePath)
});

watcher.on('change', function (path: string) {
if (!/(tsx?|vue|jsx?)$/.test(path)) {
return;
}
const ver = versions.get(path) || 0;
versions.set(path, ver + 1);
});

function updateCurrentTextDocument(doc: TextDocument) {
const fileFsPath = getFileFsPath(doc.uri);
Expand Down Expand Up @@ -198,7 +211,10 @@ export function getServiceHost(workspacePath: string, jsDocuments: LanguageModel
return {
updateCurrentTextDocument,
getScriptDocByFsPath,
getService: () => jsLanguageService
dispose: () => {
watcher.close();
jsLanguageService.dispose();
},
};
}

Expand Down
Loading

0 comments on commit d342dff

Please sign in to comment.