forked from vuejs/vetur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vueInfoService.ts
103 lines (93 loc) · 2.04 KB
/
vueInfoService.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { TextDocument } from 'vscode-languageserver-textdocument';
import { getFileFsPath } from '../utils/paths';
import { Definition } from 'vscode-languageserver-types';
import { LanguageModes } from '../embeddedSupport/languageModes';
/**
* State associated with a specific Vue file
* The state is shared between different modes
*/
export interface VueFileInfo {
/**
* The defualt export component info from script section
*/
componentInfo: ComponentInfo;
}
export interface ComponentInfo {
name?: string;
definition?: Definition;
insertInOptionAPIPos?: number;
componentsDefine?: {
start: number;
end: number;
insertPos: number;
};
childComponents?: ChildComponent[];
/**
* Todo: Extract type info in cases like
* props: {
* foo: String
* }
*/
props?: PropInfo[];
data?: DataInfo[];
computed?: ComputedInfo[];
methods?: MethodInfo[];
}
export interface ChildComponent {
name: string;
documentation?: string;
definition?: {
path: string;
start: number;
end: number;
};
global: boolean;
info?: VueFileInfo;
}
export interface PropInfo {
name: string;
/**
* `true` if
* props: {
* foo: { ... }
* }
*
* `false` if
* - `props: ['foo']`
* - `props: { foo: String }`
*
*/
hasObjectValidator: boolean;
required: boolean;
isBoundToModel: boolean;
documentation?: string;
typeString?: string;
}
export interface DataInfo {
name: string;
documentation?: string;
}
export interface ComputedInfo {
name: string;
documentation?: string;
}
export interface MethodInfo {
name: string;
documentation?: string;
}
export class VueInfoService {
private languageModes: LanguageModes;
constructor() {}
init(languageModes: LanguageModes) {
this.languageModes = languageModes;
}
getInfo(doc: TextDocument) {
let info: VueFileInfo | undefined;
this.languageModes.getAllLanguageModeRangesInDocument(doc).forEach(m => {
if (m.mode.getFileInfo) {
info = m.mode.getFileInfo(doc);
}
});
return info;
}
}