Skip to content

Commit 0ec4d30

Browse files
authored
Fixing exception on unsaved file (#60362)
1 parent 11b2930 commit 0ec4d30

File tree

3 files changed

+288
-0
lines changed

3 files changed

+288
-0
lines changed

src/server/session.ts

+2
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ import {
156156
indent,
157157
isConfigFile,
158158
isConfiguredProject,
159+
isDynamicFileName,
159160
isExternalProject,
160161
isInferredProject,
161162
ITypingsInstaller,
@@ -2981,6 +2982,7 @@ export class Session<TMessage = string> implements EventSender {
29812982
}
29822983
private getPasteEdits(args: protocol.GetPasteEditsRequestArgs): protocol.PasteEditsAction | undefined {
29832984
const { file, project } = this.getFileAndProject(args);
2985+
if (isDynamicFileName(file)) return undefined;
29842986
const copiedFrom = args.copiedFrom
29852987
? { file: args.copiedFrom.file, range: args.copiedFrom.spans.map(copies => this.getRange({ file: args.copiedFrom!.file, startLine: copies.start.line, startOffset: copies.start.offset, endLine: copies.end.line, endOffset: copies.end.offset }, project.getScriptInfoForNormalizedPath(toNormalizedPath(args.copiedFrom!.file))!)) }
29862988
: undefined;

src/testRunner/unittests/tsserver/pasteEdits.ts

+38
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,42 @@ const f = r + s;`;
4646
verifyGetErrRequest({ session, files: [target.path] });
4747
baselineTsserverLogs("pasteEdits", "adds paste edits", session);
4848
});
49+
it("should not error", () => {
50+
const file1: File = {
51+
path: "/home/src/projects/project/file1.ts",
52+
content: `export const r = 1;
53+
console.log(r);`,
54+
};
55+
const tsconfig: File = {
56+
path: "/home/src/projects/project/tsconfig.json",
57+
content: "{}",
58+
};
59+
const host = TestServerHost.createServerHost([file1, tsconfig]);
60+
const session = new TestSession(host);
61+
session.executeCommandSeq<ts.server.protocol.UpdateOpenRequest>({
62+
command: ts.server.protocol.CommandTypes.UpdateOpen,
63+
arguments: {
64+
changedFiles: [],
65+
closedFiles: [],
66+
openFiles: [
67+
{
68+
file: "^/untitled/ts-nul-authority/Untitled-1",
69+
fileContent: "function foo(){}\r\n \r\n",
70+
scriptKindName: "TS",
71+
},
72+
],
73+
},
74+
});
75+
session.executeCommandSeq<ts.server.protocol.GetPasteEditsRequest>({
76+
command: ts.server.protocol.CommandTypes.GetPasteEdits,
77+
arguments: {
78+
file: "^/untitled/ts-nul-authority/Untitled-1",
79+
pastedText: ["console.log(r);"],
80+
pasteLocations: [{ start: { line: 1, offset: 0 }, end: { line: 1, offset: 0 } }],
81+
copiedFrom: { file: file1.path, spans: [{ start: { line: 2, offset: 0 }, end: { line: 2, offset: 13 } }] },
82+
},
83+
});
84+
verifyGetErrRequest({ session, files: ["^/untitled/ts-nul-authority/Untitled-1"] });
85+
baselineTsserverLogs("pasteEdits", "should not error", session);
86+
});
4987
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
Info seq [hh:mm:ss:mss] currentDirectory:: /home/src/Vscode/Projects/bin useCaseSensitiveFileNames:: false
2+
Info seq [hh:mm:ss:mss] libs Location:: /home/src/tslibs/TS/Lib
3+
Info seq [hh:mm:ss:mss] globalTypingsCacheLocation:: /home/src/Library/Caches/typescript
4+
Info seq [hh:mm:ss:mss] Provided types map file "/home/src/tslibs/TS/Lib/typesMap.json" doesn't exist
5+
Before request
6+
//// [/home/src/projects/project/file1.ts]
7+
export const r = 1;
8+
console.log(r);
9+
10+
//// [/home/src/projects/project/tsconfig.json]
11+
{}
12+
13+
//// [/home/src/tslibs/TS/Lib/lib.d.ts]
14+
/// <reference no-default-lib="true"/>
15+
interface Boolean {}
16+
interface Function {}
17+
interface CallableFunction {}
18+
interface NewableFunction {}
19+
interface IArguments {}
20+
interface Number { toExponential: any; }
21+
interface Object {}
22+
interface RegExp {}
23+
interface String { charAt: any; }
24+
interface Array<T> { length: number; [n: number]: T; }
25+
interface ReadonlyArray<T> {}
26+
declare const console: { log(msg: any): void; };
27+
28+
29+
Info seq [hh:mm:ss:mss] request:
30+
{
31+
"command": "updateOpen",
32+
"arguments": {
33+
"changedFiles": [],
34+
"closedFiles": [],
35+
"openFiles": [
36+
{
37+
"file": "^/untitled/ts-nul-authority/Untitled-1",
38+
"fileContent": "function foo(){}\r\n \r\n",
39+
"scriptKindName": "TS"
40+
}
41+
]
42+
},
43+
"seq": 1,
44+
"type": "request"
45+
}
46+
Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: ^/untitled/ts-nul-authority/Untitled-1 ProjectRootPath: undefined:: Result: undefined
47+
Info seq [hh:mm:ss:mss] Creating InferredProject: /dev/null/inferredProject1*, currentDirectory: /home/src/Vscode/Projects/bin
48+
Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /dev/null/inferredProject1*
49+
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.d.ts 500 undefined WatchType: Closed Script info
50+
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/Vscode/Projects/bin/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots
51+
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/Vscode/Projects/bin/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots
52+
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/Vscode/Projects/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots
53+
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/Vscode/Projects/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots
54+
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/Vscode/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots
55+
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/Vscode/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots
56+
Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /dev/null/inferredProject1* projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed:: *ms
57+
Info seq [hh:mm:ss:mss] Project '/dev/null/inferredProject1*' (Inferred)
58+
Info seq [hh:mm:ss:mss] Files (2)
59+
/home/src/tslibs/TS/Lib/lib.d.ts Text-1 "/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };"
60+
^/untitled/ts-nul-authority/Untitled-1 SVC-1-0 "function foo(){}\r\n \r\n"
61+
62+
63+
../../../tslibs/TS/Lib/lib.d.ts
64+
Default library for target 'es5'
65+
^/untitled/ts-nul-authority/Untitled-1
66+
Root file specified for compilation
67+
68+
Info seq [hh:mm:ss:mss] -----------------------------------------------
69+
Info seq [hh:mm:ss:mss] Project '/dev/null/inferredProject1*' (Inferred)
70+
Info seq [hh:mm:ss:mss] Files (2)
71+
72+
Info seq [hh:mm:ss:mss] -----------------------------------------------
73+
Info seq [hh:mm:ss:mss] Open files:
74+
Info seq [hh:mm:ss:mss] FileName: ^/untitled/ts-nul-authority/Untitled-1 ProjectRootPath: undefined
75+
Info seq [hh:mm:ss:mss] Projects: /dev/null/inferredProject1*
76+
Info seq [hh:mm:ss:mss] response:
77+
{
78+
"response": true,
79+
"responseRequired": true,
80+
"performanceData": {
81+
"updateGraphDurationMs": *
82+
}
83+
}
84+
After request
85+
86+
PolledWatches::
87+
/home/src/Vscode/Projects/bin/node_modules/@types: *new*
88+
{"pollingInterval":500}
89+
/home/src/Vscode/Projects/node_modules/@types: *new*
90+
{"pollingInterval":500}
91+
/home/src/Vscode/node_modules/@types: *new*
92+
{"pollingInterval":500}
93+
94+
FsWatches::
95+
/home/src/tslibs/TS/Lib/lib.d.ts: *new*
96+
{}
97+
98+
Projects::
99+
/dev/null/inferredProject1* (Inferred) *new*
100+
projectStateVersion: 1
101+
projectProgramVersion: 1
102+
autoImportProviderHost: false
103+
104+
ScriptInfos::
105+
/home/src/tslibs/TS/Lib/lib.d.ts *new*
106+
version: Text-1
107+
containingProjects: 1
108+
/dev/null/inferredProject1*
109+
^/untitled/ts-nul-authority/Untitled-1 (Dynamic) (Open) *new*
110+
version: SVC-1-0
111+
containingProjects: 1
112+
/dev/null/inferredProject1* *default*
113+
114+
Before request
115+
116+
Info seq [hh:mm:ss:mss] request:
117+
{
118+
"command": "getPasteEdits",
119+
"arguments": {
120+
"file": "^/untitled/ts-nul-authority/Untitled-1",
121+
"pastedText": [
122+
"console.log(r);"
123+
],
124+
"pasteLocations": [
125+
{
126+
"start": {
127+
"line": 1,
128+
"offset": 0
129+
},
130+
"end": {
131+
"line": 1,
132+
"offset": 0
133+
}
134+
}
135+
],
136+
"copiedFrom": {
137+
"file": "/home/src/projects/project/file1.ts",
138+
"spans": [
139+
{
140+
"start": {
141+
"line": 2,
142+
"offset": 0
143+
},
144+
"end": {
145+
"line": 2,
146+
"offset": 13
147+
}
148+
}
149+
]
150+
}
151+
},
152+
"seq": 2,
153+
"type": "request"
154+
}
155+
Info seq [hh:mm:ss:mss] response:
156+
{
157+
"responseRequired": true
158+
}
159+
After request
160+
161+
Before request
162+
163+
Info seq [hh:mm:ss:mss] request:
164+
{
165+
"command": "geterr",
166+
"arguments": {
167+
"delay": 0,
168+
"files": [
169+
"^/untitled/ts-nul-authority/Untitled-1"
170+
]
171+
},
172+
"seq": 3,
173+
"type": "request"
174+
}
175+
After request
176+
177+
Timeout callback:: count: 1
178+
1: checkOne *new*
179+
180+
Before running Timeout callback:: count: 1
181+
1: checkOne
182+
183+
Info seq [hh:mm:ss:mss] event:
184+
{
185+
"seq": 0,
186+
"type": "event",
187+
"event": "syntaxDiag",
188+
"body": {
189+
"file": "^/untitled/ts-nul-authority/Untitled-1",
190+
"diagnostics": []
191+
}
192+
}
193+
After running Timeout callback:: count: 0
194+
195+
Immedidate callback:: count: 1
196+
1: semanticCheck *new*
197+
198+
Before running Immedidate callback:: count: 1
199+
1: semanticCheck
200+
201+
Info seq [hh:mm:ss:mss] event:
202+
{
203+
"seq": 0,
204+
"type": "event",
205+
"event": "semanticDiag",
206+
"body": {
207+
"file": "^/untitled/ts-nul-authority/Untitled-1",
208+
"diagnostics": []
209+
}
210+
}
211+
After running Immedidate callback:: count: 1
212+
213+
Immedidate callback:: count: 1
214+
2: suggestionCheck *new*
215+
216+
Before running Immedidate callback:: count: 1
217+
2: suggestionCheck
218+
219+
Info seq [hh:mm:ss:mss] event:
220+
{
221+
"seq": 0,
222+
"type": "event",
223+
"event": "suggestionDiag",
224+
"body": {
225+
"file": "^/untitled/ts-nul-authority/Untitled-1",
226+
"diagnostics": []
227+
}
228+
}
229+
Info seq [hh:mm:ss:mss] event:
230+
{
231+
"seq": 0,
232+
"type": "event",
233+
"event": "requestCompleted",
234+
"body": {
235+
"request_seq": 3,
236+
"performanceData": {
237+
"diagnosticsDuration": [
238+
{
239+
"syntaxDiag": *,
240+
"semanticDiag": *,
241+
"suggestionDiag": *,
242+
"file": "^/untitled/ts-nul-authority/Untitled-1"
243+
}
244+
]
245+
}
246+
}
247+
}
248+
After running Immedidate callback:: count: 0

0 commit comments

Comments
 (0)