Skip to content

Commit

Permalink
Merge pull request #801 from vuejs/DocumentService
Browse files Browse the repository at this point in the history
[WIP] Initial cut for document manager. #800
  • Loading branch information
octref authored Jun 3, 2018
2 parents bec3578 + 67d327d commit 9952064
Show file tree
Hide file tree
Showing 15 changed files with 388 additions and 394 deletions.
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"prettier-eslint": "^8.8.1",
"stylus": "^0.54.5",
"stylus-supremacy": "^2.10.0",
"typescript": "^2.8.1",
"typescript": "^2.8.3",
"vscode-css-languageservice": "^3.0.3",
"vscode-emmet-helper": "^1.1.19",
"vscode-languageserver": "^3.5.0",
Expand Down
3 changes: 1 addition & 2 deletions server/src/modes/languageModes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ import {
import {
Color, ColorInformation, ColorPresentation
} from 'vscode-languageserver-protocol/lib/protocol.colorProvider.proposed';
import { DocumentContext } from '../service';

import { getLanguageModelCache, LanguageModelCache } from './languageModelCache';
import { getDocumentRegions, VueDocumentRegions } from './embeddedSupport';
import { getVueMode } from './vue';
import { getCSSMode, getSCSSMode, getLESSMode, getPostCSSMode } from './style';
import { getJavascriptMode } from './script/javascript';
import { getVueHTMLMode } from './template';

import { getStylusMode } from './style/stylus';
import { DocumentContext } from '../types';

export interface LanguageMode {
getId(): string;
Expand Down
3 changes: 1 addition & 2 deletions server/src/modes/nullMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ export const NULL_SIGNATURE = {

export const NULL_COMPLETION = {
isIncomplete: false,
items: [],
label: ''
items: []
};

export const nullMode: LanguageMode = {
Expand Down
9 changes: 6 additions & 3 deletions server/src/modes/script/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import Uri from 'vscode-uri';
import * as ts from 'typescript';
import * as _ from 'lodash';

import { nullMode, NULL_SIGNATURE, NULL_COMPLETION } from '../nullMode';
import { nullMode, NULL_SIGNATURE } from '../nullMode';

// Todo: After upgrading to LS server 4.0, use CompletionContext for filtering trigger chars
// https://microsoft.github.io/language-server-protocol/specification#completion-request-leftwards_arrow_with_hook
Expand All @@ -48,7 +48,10 @@ export function getJavascriptMode(
workspacePath: string | null | undefined
): ScriptMode {
if (!workspacePath) {
return { ...nullMode, findComponents: () => [] };
return {
...nullMode,
findComponents: () => []
};
}
const jsDocuments = getLanguageModelCache(10, 60, document => {
const vueDocument = documentRegions.get(document);
Expand Down Expand Up @@ -142,7 +145,7 @@ export function getJavascriptMode(
doResolve(doc: TextDocument, item: CompletionItem): CompletionItem {
const { service } = updateCurrentTextDocument(doc);
if (!languageServiceIncludesFile(service, doc.uri)) {
return NULL_COMPLETION;
return item;
}

const fileFsPath = getFileFsPath(doc.uri);
Expand Down
2 changes: 1 addition & 1 deletion server/src/modes/script/serviceHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,4 @@ function getParsedConfig(workspacePath: string) {
/*resolutionStack*/ undefined,
[{ extension: 'vue', isMixedContent: true }]
);
}
}
7 changes: 3 additions & 4 deletions server/src/modes/template/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as _ from 'lodash';

import { LanguageModelCache, getLanguageModelCache } from '../languageModelCache';
import { DocumentContext } from '../../service';
import { TextDocument, Position, Range, FormattingOptions } from 'vscode-languageserver-types';
import { LanguageMode } from '../languageModes';
import { VueDocumentRegions } from '../embeddedSupport';

import { HTMLDocument } from './parser/htmlParser';
import { doComplete } from './services/htmlCompletion';
import { doHover } from './services/htmlHover';
Expand All @@ -17,8 +17,7 @@ import { findDefinition } from './services/htmlDefinition';
import { getTagProviderSettings } from './tagProviders';
import { ScriptMode } from '../script/javascript';
import { getComponentTags, getEnabledTagProviders } from './tagProviders';

import * as _ from 'lodash';
import { DocumentContext } from '../../types';

type DocumentRegionCache = LanguageModelCache<VueDocumentRegions>;

Expand Down
3 changes: 1 addition & 2 deletions server/src/modes/template/services/htmlLinks.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { TokenType, createScanner } from '../parser/htmlScanner';
import { TextDocument, Range, DocumentLink } from 'vscode-languageserver-types';
import Uri from 'vscode-uri';

import { DocumentContext } from '../../../service';
import { DocumentContext } from '../../../types';

function stripQuotes(url: string): string {
return url.replace(/^'([^']*)'$/, (substr, match1) => match1).replace(/^"([^"]*)"$/, (substr, match1) => match1);
Expand Down
2 changes: 1 addition & 1 deletion server/src/modes/template/test/links.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import * as assert from 'assert';
import { TextDocument } from 'vscode-languageserver-types';
import * as url from 'url';

import { DocumentContext } from '../../../service';
import { findDocumentLinks } from '../services/htmlLinks';
import { DocumentContext } from '../../../types';

suite('HTML Link Detection', () => {
function getDocumentContext(documentUrl: string): DocumentContext {
Expand Down
23 changes: 0 additions & 23 deletions server/src/service/formatting.ts

This file was deleted.

195 changes: 0 additions & 195 deletions server/src/service/index.ts

This file was deleted.

32 changes: 32 additions & 0 deletions server/src/services/document.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { IConnection, TextDocuments } from 'vscode-languageserver';

/**
* Service responsible for managing documents being syned through LSP
* Todo - Switch to incremental sync
*/
export class DocumentService {
private documents: TextDocuments;

constructor() {
this.documents = new TextDocuments();
}

listen(conn: IConnection) {
this.documents.listen(conn);
}

getDocument(uri: string) {
return this.documents.get(uri);
}

getAllDocuments() {
return this.documents.all();
}

get onDidChangeContent() {
return this.documents.onDidChangeContent;
}
get onDidClose() {
return this.documents.onDidClose;
}
}
Loading

0 comments on commit 9952064

Please sign in to comment.