1 | import { TextDocumentContentChangeEvent } from 'vscode-languageserver-protocol';
|
2 | import URI from '../common/uri';
|
3 | import { ContributionProvider } from './contribution-provider';
|
4 | import { Event, Emitter } from './event';
|
5 | import { Disposable } from './disposable';
|
6 | import { MaybePromise } from './types';
|
7 | import { CancellationToken } from './cancellation';
|
8 | import { ApplicationError } from './application-error';
|
9 | import { ReadableStream, Readable } from './stream';
|
10 | import { SyncReferenceCollection, Reference } from './reference';
|
11 | export interface ResourceVersion {
|
12 | }
|
13 | export interface ResourceReadOptions {
|
14 | encoding?: string;
|
15 | }
|
16 | export interface ResourceSaveOptions {
|
17 | encoding?: string;
|
18 | overwriteEncoding?: boolean;
|
19 | version?: ResourceVersion;
|
20 | }
|
21 | export interface Resource extends Disposable {
|
22 | readonly uri: URI;
|
23 | |
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | readonly version?: ResourceVersion | undefined;
|
30 | |
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | readonly encoding?: string | undefined;
|
37 | |
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | readContents(options?: ResourceReadOptions): Promise<string>;
|
46 | |
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | readStream?(options?: ResourceReadOptions): Promise<ReadableStream<string>>;
|
55 | |
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | saveContents?(content: string, options?: ResourceSaveOptions): Promise<void>;
|
67 | |
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 | saveStream?(content: Readable<string>, options?: ResourceSaveOptions): Promise<void>;
|
79 | |
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 | saveContentChanges?(changes: TextDocumentContentChangeEvent[], options?: ResourceSaveOptions): Promise<void>;
|
90 | readonly onDidChangeContents?: Event<void>;
|
91 | guessEncoding?(): Promise<string | undefined>;
|
92 | }
|
93 | export declare namespace Resource {
|
94 | interface SaveContext {
|
95 | contentLength: number;
|
96 | content: string | Readable<string>;
|
97 | changes?: TextDocumentContentChangeEvent[];
|
98 | options?: ResourceSaveOptions;
|
99 | }
|
100 | function save(resource: Resource, context: SaveContext, token?: CancellationToken): Promise<void>;
|
101 | function trySaveContentChanges(resource: Resource, context: SaveContext): Promise<boolean>;
|
102 | function shouldSaveContent(resource: Resource, { contentLength, changes }: SaveContext): boolean;
|
103 | }
|
104 | export declare namespace ResourceError {
|
105 | const NotFound: ApplicationError.Constructor<-40000, {
|
106 | uri: URI;
|
107 | }>;
|
108 | const OutOfSync: ApplicationError.Constructor<-40001, {
|
109 | uri: URI;
|
110 | }>;
|
111 | }
|
112 | export declare const ResourceResolver: unique symbol;
|
113 | export interface ResourceResolver {
|
114 | |
115 |
|
116 |
|
117 | resolve(uri: URI): MaybePromise<Resource>;
|
118 | }
|
119 | export declare const ResourceProvider: unique symbol;
|
120 | export declare type ResourceProvider = (uri: URI) => Promise<Resource>;
|
121 | export declare class DefaultResourceProvider {
|
122 | protected readonly resolversProvider: ContributionProvider<ResourceResolver>;
|
123 | constructor(resolversProvider: ContributionProvider<ResourceResolver>);
|
124 | /**
|
125 | * Reject if a resource cannot be provided.
|
126 | */
|
127 | get(uri: URI): Promise<Resource>;
|
128 | }
|
129 | export declare class MutableResource implements Resource {
|
130 | readonly uri: URI;
|
131 | private contents;
|
132 | constructor(uri: URI);
|
133 | dispose(): void;
|
134 | readContents(): Promise<string>;
|
135 | saveContents(contents: string): Promise<void>;
|
136 | protected readonly onDidChangeContentsEmitter: Emitter<void>;
|
137 | readonly onDidChangeContents: Event<void>;
|
138 | protected fireDidChangeContents(): void;
|
139 | }
|
140 | export declare class ReferenceMutableResource implements Resource {
|
141 | protected reference: Reference<MutableResource>;
|
142 | constructor(reference: Reference<MutableResource>);
|
143 | get uri(): URI;
|
144 | get onDidChangeContents(): Event<void>;
|
145 | dispose(): void;
|
146 | readContents(): Promise<string>;
|
147 | saveContents(contents: string): Promise<void>;
|
148 | }
|
149 | export declare class InMemoryResources implements ResourceResolver {
|
150 | protected readonly resources: SyncReferenceCollection<string, MutableResource>;
|
151 | add(uri: URI, contents: string): Resource;
|
152 | update(uri: URI, contents: string): Resource;
|
153 | resolve(uri: URI): Resource;
|
154 | protected acquire(uri: string): ReferenceMutableResource;
|
155 | }
|
156 | export declare const MEMORY_TEXT = "mem-txt";
|
157 |
|
158 |
|
159 |
|
160 | export declare class InMemoryTextResource implements Resource {
|
161 | readonly uri: URI;
|
162 | constructor(uri: URI);
|
163 | readContents(options?: {
|
164 | encoding?: string | undefined;
|
165 | } | undefined): Promise<string>;
|
166 | dispose(): void;
|
167 | }
|
168 | /**
|
169 | * ResourceResolver implementation for 'mem-txt' URI scheme.
|
170 | */
|
171 | export declare class InMemoryTextResourceResolver implements ResourceResolver {
|
172 | resolve(uri: URI): MaybePromise<Resource>;
|
173 | }
|
174 | export declare const UNTITLED_SCHEME = "untitled";
|
175 | export declare class UntitledResourceResolver implements ResourceResolver {
|
176 | protected readonly resources: Map<string, UntitledResource>;
|
177 | has(uri: URI): boolean;
|
178 | resolve(uri: URI): Promise<UntitledResource>;
|
179 | createUntitledResource(content?: string, extension?: string, uri?: URI): Promise<UntitledResource>;
|
180 | createUntitledURI(extension?: string, parent?: URI): URI;
|
181 | }
|
182 | export declare class UntitledResource implements Resource {
|
183 | private resources;
|
184 | uri: URI;
|
185 | private content?;
|
186 | protected readonly onDidChangeContentsEmitter: Emitter<void>;
|
187 | get onDidChangeContents(): Event<void>;
|
188 | constructor(resources: Map<string, UntitledResource>, uri: URI, content?: string | undefined);
|
189 | dispose(): void;
|
190 | readContents(options?: {
|
191 | encoding?: string | undefined;
|
192 | } | undefined): Promise<string>;
|
193 | saveContents(content: string, options?: {
|
194 | encoding?: string;
|
195 | overwriteEncoding?: boolean;
|
196 | }): Promise<void>;
|
197 | protected fireDidChangeContents(): void;
|
198 | get version(): ResourceVersion | undefined;
|
199 | get encoding(): string | undefined;
|
200 | }
|
201 | /**
|
202 | * @deprecated Since 1.27.0. Please use `UntitledResourceResolver.createUntitledURI` instead.
|
203 | */
|
204 | export declare function createUntitledURI(extension?: string, parent?: URI): URI;
|
205 | //# sourceMappingURL=resource.d.ts.map |
\ | No newline at end of file |