Skip to content

Commit

Permalink
Correct inform TS language service of updated js/ts docs. Fix #355
Browse files Browse the repository at this point in the history
  • Loading branch information
octref committed Jun 4, 2018
1 parent 9952064 commit 6ef2132
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
4 changes: 2 additions & 2 deletions client/vueMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ export function activate(context: ExtensionContext) {
const clientOptions: LanguageClientOptions = {
documentSelector,
synchronize: {
// the settings to synchronize
configurationSection: ['vetur', 'emmet', 'html', 'javascript', 'typescript', 'prettier', 'stylusSupremacy']
configurationSection: ['vetur', 'emmet', 'html', 'javascript', 'typescript', 'prettier', 'stylusSupremacy'],
fileEvents: vscode.workspace.createFileSystemWatcher('{**/*.js,**/*.ts}', true, false, true)
},
initializationOptions: {
config
Expand Down
1 change: 1 addition & 0 deletions server/src/modes/languageModes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface LanguageMode {
findDocumentColors?(document: TextDocument): ColorInformation[];
getColorPresentations?(document: TextDocument, color: Color, range: Range): ColorPresentation[];

onDocumentChanged?(filePath: string): void;
onDocumentRemoved(document: TextDocument): void;
dispose(): void;
}
Expand Down
3 changes: 3 additions & 0 deletions server/src/modes/script/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ export function getJavascriptMode(
onDocumentRemoved(document: TextDocument) {
jsDocuments.onDocumentRemoved(document);
},
onDocumentChanged(filePath: string) {
serviceHost.updateTypescriptDocument(filePath);
},
dispose() {
serviceHost.dispose();
jsDocuments.dispose();
Expand Down
13 changes: 8 additions & 5 deletions server/src/modes/script/serviceHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const vueSys: ts.System = {

if (ts.sys.realpath) {
const realpath = ts.sys.realpath;
vueSys.realpath = function (path) {
vueSys.realpath = function(path) {
if (isVueProject(path)) {
return realpath(path.slice(0, -3)) + '.ts';
}
Expand All @@ -55,10 +55,7 @@ const defaultCompilerOptions: ts.CompilerOptions = {
allowSyntheticDefaultImports: true
};

export function getServiceHost(
workspacePath: string,
jsDocuments: LanguageModelCache<TextDocument>
) {
export function getServiceHost(workspacePath: string, jsDocuments: LanguageModelCache<TextDocument>) {
let currentScriptDoc: TextDocument;
const versions = new Map<string, number>();
const scriptDocs = new Map<string, TextDocument>();
Expand Down Expand Up @@ -98,6 +95,11 @@ export function getServiceHost(
};
}

function updateTypescriptDocument(filePath: string) {
const ver = versions.get(filePath) || 0;
versions.set(filePath, ver + 1);
}

function getScriptDocByFsPath(fsPath: string) {
return scriptDocs.get(fsPath);
}
Expand Down Expand Up @@ -200,6 +202,7 @@ export function getServiceHost(
let jsLanguageService = ts.createLanguageService(host);
return {
updateCurrentTextDocument,
updateTypescriptDocument,
getScriptDocByFsPath,
dispose: () => {
jsLanguageService.dispose();
Expand Down
12 changes: 11 additions & 1 deletion server/src/services/vls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import {
TextDocumentPositionParams,
DocumentLinkParams,
DocumentFormattingParams,
DidChangeConfigurationParams
DidChangeConfigurationParams,
FileChangeType
} from 'vscode-languageserver';
import Uri from 'vscode-uri';
import * as path from 'path';
Expand Down Expand Up @@ -103,6 +104,15 @@ export class VLS {
this.documentService.onDidClose(e => {
this.removeDocument(e.document);
});
this.lspConnection.onDidChangeWatchedFiles(({ changes }) => {
const jsMode = this.languageModes.getMode('javascript');
changes.forEach(c => {
if (c.type === FileChangeType.Changed) {
const fsPath = Uri.parse(c.uri).fsPath;
jsMode.onDocumentChanged!(fsPath);
}
});
});
}

configure(config: any): void {
Expand Down
1 change: 0 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"quotemark": [true, "single", "avoid-escape"],
"whitespace": true,
"semicolon": [true, "always"],
"space-before-function-paren": [true, {"anonymous": "always", "named": "never"}],
"triple-equals": true,
"variable-name": [true, "ban-keywords", "check-format", "allow-leading-underscore"]
},
Expand Down

0 comments on commit 6ef2132

Please sign in to comment.