Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit11b73ec

Browse files
authored
Fixing a case when text is pasted into a blank file (microsoft#58595)
1 parent84ab39d commit11b73ec

File tree

6 files changed

+387
-45
lines changed

6 files changed

+387
-45
lines changed

‎src/server/project.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,13 +2240,13 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
22402240
/**@internal */
22412241
runWithTemporaryFileUpdate(rootFile:string,updatedText:string,cb:(updatedProgram:Program,originalProgram:Program|undefined,updatedFile:SourceFile)=>void){
22422242
constoriginalProgram=this.program;
2243-
constoriginalText=this.program?.getSourceFile(rootFile)?.getText();
2244-
Debug.assert(this.program&&this.program.getSourceFile(rootFile)&&originalText);
2243+
constrootSourceFile=Debug.checkDefined(this.program?.getSourceFile(rootFile),"Expected file to be part of program");
2244+
constoriginalText=Debug.checkDefined(rootSourceFile.getText());
22452245

2246-
this.getScriptInfo(rootFile)?.editContent(0,this.program.getSourceFile(rootFile)!.getText().length,updatedText);
2246+
this.getScriptInfo(rootFile)?.editContent(0,originalText.length,updatedText);
22472247
this.updateGraph();
2248-
cb(this.program,originalProgram,(this.program?.getSourceFile(rootFile))!);
2249-
this.getScriptInfo(rootFile)?.editContent(0,this.program.getSourceFile(rootFile)!.getText().length,originalText);
2248+
cb(this.program!,originalProgram,(this.program?.getSourceFile(rootFile))!);
2249+
this.getScriptInfo(rootFile)?.editContent(0,this.program!.getSourceFile(rootFile)!.getText().length,originalText);
22502250
}
22512251

22522252
/**@internal */

‎src/services/pasteEdits.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,6 @@ function pasteEdits(
6363
if(pastedText.length!==pasteLocations.length){
6464
actualPastedText=pastedText.length===1 ?pastedText :[pastedText.join("\n")];
6565
}
66-
pasteLocations.forEach((paste,i)=>{
67-
changes.replaceRangeWithText(
68-
targetFile,
69-
{pos:paste.pos,end:paste.end},
70-
actualPastedText ?
71-
actualPastedText[0] :pastedText[i],
72-
);
73-
});
7466

7567
conststatements:Statement[]=[];
7668

@@ -112,4 +104,12 @@ function pasteEdits(
112104
}
113105
importAdder.writeFixes(changes,getQuotePreference(copiedFrom ?copiedFrom.file :targetFile,preferences));
114106
});
107+
pasteLocations.forEach((paste,i)=>{
108+
changes.replaceRangeWithText(
109+
targetFile,
110+
{pos:paste.pos,end:paste.end},
111+
actualPastedText ?
112+
actualPastedText[0] :pastedText[i],
113+
);
114+
});
115115
}
Lines changed: 314 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,314 @@
1+
currentDirectory::/useCaseSensitiveFileNames:false
2+
Infoseq[hh:mm:ss:mss]Providedtypesmapfile"/typesMap.json"doesn't exist
3+
//// [/a.ts]
4+
exportconstabc=10;
5+
6+
//// [/b.ts]
7+
import{abc}from"./a";
8+
console.log(abc);
9+
10+
//// [/c.ts]
11+
12+
13+
//// [/lib.d.ts]
14+
lib.d.ts-Text
15+
16+
//// [/lib.decorators.d.ts]
17+
lib.decorators.d.ts-Text
18+
19+
//// [/lib.decorators.legacy.d.ts]
20+
lib.decorators.legacy.d.ts-Text
21+
22+
//// [/tsconfig.json]
23+
{"files":["c.ts","a.ts","b.ts"]}
24+
25+
26+
Infoseq[hh:mm:ss:mss] request:
27+
{
28+
"seq":0,
29+
"type":"request",
30+
"arguments":{
31+
"file":"/c.ts"
32+
},
33+
"command":"open"
34+
}
35+
Infoseq[hh:mm:ss:mss] getConfigFileNameForFile:: File:/c.tsProjectRootPath:undefined::Result:/tsconfig.json
36+
Infoseq[hh:mm:ss:mss]Creatingconfigurationproject/tsconfig.json
37+
Infoseq[hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo:/tsconfig.json2000undefinedProject:/tsconfig.json WatchType:Configfile
38+
Infoseq[hh:mm:ss:mss] event:
39+
{
40+
"seq":0,
41+
"type":"event",
42+
"event":"projectLoadingStart",
43+
"body":{
44+
"projectName":"/tsconfig.json",
45+
"reason":"Creating possible configured project for /c.ts to open"
46+
}
47+
}
48+
Infoseq[hh:mm:ss:mss] Config:/tsconfig.json:{
49+
"rootNames":[
50+
"/c.ts",
51+
"/a.ts",
52+
"/b.ts"
53+
],
54+
"options":{
55+
"configFilePath":"/tsconfig.json"
56+
}
57+
}
58+
Infoseq[hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo:/a.ts500undefinedWatchType:ClosedScriptinfo
59+
Infoseq[hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo:/b.ts500undefinedWatchType:ClosedScriptinfo
60+
Infoseq[hh:mm:ss:mss]Starting updateGraphWorker: Project:/tsconfig.json
61+
Infoseq[hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo:/lib.d.ts500undefinedWatchType:ClosedScriptinfo
62+
Infoseq[hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo:/lib.decorators.d.ts500undefinedWatchType:ClosedScriptinfo
63+
Infoseq[hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo:/lib.decorators.legacy.d.ts500undefinedWatchType:ClosedScriptinfo
64+
Infoseq[hh:mm:ss:mss]Finishing updateGraphWorker: Project:/tsconfig.jsonprojectStateVersion:1projectProgramVersion:0structureChanged:truestructureIsReused::NotElapsed::*ms
65+
Infoseq[hh:mm:ss:mss]Project'/tsconfig.json'(Configured)
66+
Infoseq[hh:mm:ss:mss]Files(6)
67+
/lib.d.tsText-1lib.d.ts-Text
68+
/lib.decorators.d.tsText-1lib.decorators.d.ts-Text
69+
/lib.decorators.legacy.d.tsText-1lib.decorators.legacy.d.ts-Text
70+
/c.tsSVC-1-0""
71+
/a.tsText-1"export const abc = 10;"
72+
/b.tsText-1"import { abc } from \"./a\";\nconsole.log(abc);"
73+
74+
75+
lib.d.ts
76+
Defaultlibraryfortarget'es5'
77+
lib.decorators.d.ts
78+
Libraryreferencedvia'decorators'fromfile 'lib.d.ts'
79+
lib.decorators.legacy.d.ts
80+
Libraryreferencedvia'decorators.legacy'fromfile 'lib.d.ts'
81+
c.ts
82+
Partof'files'listintsconfig.json
83+
a.ts
84+
Partof'files'listintsconfig.json
85+
Importedvia"./a"fromfile 'b.ts'
86+
b.ts
87+
Partof'files'listintsconfig.json
88+
89+
Infoseq[hh:mm:ss:mss]-----------------------------------------------
90+
Infoseq[hh:mm:ss:mss] event:
91+
{
92+
"seq":0,
93+
"type":"event",
94+
"event":"projectLoadingFinish",
95+
"body":{
96+
"projectName":"/tsconfig.json"
97+
}
98+
}
99+
Infoseq[hh:mm:ss:mss] event:
100+
{
101+
"seq":0,
102+
"type":"event",
103+
"event":"configFileDiag",
104+
"body":{
105+
"triggerFile":"/c.ts",
106+
"configFile":"/tsconfig.json",
107+
"diagnostics":[]
108+
}
109+
}
110+
Infoseq[hh:mm:ss:mss]Project'/tsconfig.json'(Configured)
111+
Infoseq[hh:mm:ss:mss]Files(6)
112+
113+
Infoseq[hh:mm:ss:mss]-----------------------------------------------
114+
Infoseq[hh:mm:ss:mss]Openfiles:
115+
Infoseq[hh:mm:ss:mss] FileName:/c.tsProjectRootPath:undefined
116+
Infoseq[hh:mm:ss:mss] Projects:/tsconfig.json
117+
AfterRequest
118+
watchedFiles::
119+
/a.ts:*new*
120+
{"pollingInterval":500}
121+
/b.ts:*new*
122+
{"pollingInterval":500}
123+
/lib.d.ts:*new*
124+
{"pollingInterval":500}
125+
/lib.decorators.d.ts:*new*
126+
{"pollingInterval":500}
127+
/lib.decorators.legacy.d.ts:*new*
128+
{"pollingInterval":500}
129+
/tsconfig.json:*new*
130+
{"pollingInterval":2000}
131+
132+
Projects::
133+
/tsconfig.json(Configured)*new*
134+
projectStateVersion:1
135+
projectProgramVersion:1
136+
137+
ScriptInfos::
138+
/a.ts*new*
139+
version:Text-1
140+
containingProjects:1
141+
/tsconfig.json
142+
/b.ts*new*
143+
version:Text-1
144+
containingProjects:1
145+
/tsconfig.json
146+
/c.ts(Open)*new*
147+
version:SVC-1-0
148+
containingProjects:1
149+
/tsconfig.json*default*
150+
/lib.d.ts*new*
151+
version:Text-1
152+
containingProjects:1
153+
/tsconfig.json
154+
/lib.decorators.d.ts*new*
155+
version:Text-1
156+
containingProjects:1
157+
/tsconfig.json
158+
/lib.decorators.legacy.d.ts*new*
159+
version:Text-1
160+
containingProjects:1
161+
/tsconfig.json
162+
163+
Infoseq[hh:mm:ss:mss] request:
164+
{
165+
"seq":1,
166+
"type":"request",
167+
"arguments":{
168+
"formatOptions":{
169+
"indentSize":4,
170+
"tabSize":4,
171+
"newLineCharacter":"\n",
172+
"convertTabsToSpaces":true,
173+
"indentStyle":2,
174+
"insertSpaceAfterConstructor":false,
175+
"insertSpaceAfterCommaDelimiter":true,
176+
"insertSpaceAfterSemicolonInForStatements":true,
177+
"insertSpaceBeforeAndAfterBinaryOperators":true,
178+
"insertSpaceAfterKeywordsInControlFlowStatements":true,
179+
"insertSpaceAfterFunctionKeywordForAnonymousFunctions":false,
180+
"insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis":false,
181+
"insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets":false,
182+
"insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces":true,
183+
"insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces":false,
184+
"insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces":false,
185+
"insertSpaceBeforeFunctionParenthesis":false,
186+
"placeOpenBraceOnNewLineForFunctions":false,
187+
"placeOpenBraceOnNewLineForControlBlocks":false,
188+
"semicolons":"ignore",
189+
"trimTrailingWhitespace":true,
190+
"indentSwitchCase":true
191+
}
192+
},
193+
"command":"configure"
194+
}
195+
Infoseq[hh:mm:ss:mss]Formathostinformationupdated
196+
Infoseq[hh:mm:ss:mss] response:
197+
{
198+
"seq":0,
199+
"type":"response",
200+
"command":"configure",
201+
"request_seq":1,
202+
"success":true
203+
}
204+
Infoseq[hh:mm:ss:mss] request:
205+
{
206+
"seq":2,
207+
"type":"request",
208+
"arguments":{
209+
"file":"/c.ts",
210+
"pastedText":[
211+
"console.log(abc);"
212+
],
213+
"pasteLocations":[
214+
{
215+
"start":{
216+
"line":1,
217+
"offset":1
218+
},
219+
"end":{
220+
"line":1,
221+
"offset":1
222+
}
223+
}
224+
]
225+
},
226+
"command":"getPasteEdits"
227+
}
228+
Infoseq[hh:mm:ss:mss]Starting updateGraphWorker: Project:/tsconfig.json
229+
Infoseq[hh:mm:ss:mss]Finishing updateGraphWorker: Project:/tsconfig.jsonprojectStateVersion:2projectProgramVersion:1structureChanged:falsestructureIsReused::CompletelyElapsed::*ms
230+
Infoseq[hh:mm:ss:mss]Project'/tsconfig.json'(Configured)
231+
Infoseq[hh:mm:ss:mss]Files(6)
232+
/lib.d.tsText-1lib.d.ts-Text
233+
/lib.decorators.d.tsText-1lib.decorators.d.ts-Text
234+
/lib.decorators.legacy.d.tsText-1lib.decorators.legacy.d.ts-Text
235+
/c.tsSVC-1-1"console.log(abc);"
236+
/a.tsText-1"export const abc = 10;"
237+
/b.tsText-1"import { abc } from \"./a\";\nconsole.log(abc);"
238+
239+
Infoseq[hh:mm:ss:mss]-----------------------------------------------
240+
Infoseq[hh:mm:ss:mss] response:
241+
{
242+
"seq":0,
243+
"type":"response",
244+
"command":"getPasteEdits",
245+
"request_seq":2,
246+
"success":true,
247+
"performanceData":{
248+
"updateGraphDurationMs":*
249+
},
250+
"body":{
251+
"edits":[
252+
{
253+
"fileName":"/c.ts",
254+
"textChanges":[
255+
{
256+
"start":{
257+
"line":1,
258+
"offset":1
259+
},
260+
"end":{
261+
"line":1,
262+
"offset":1
263+
},
264+
"newText":"import { abc } from \"./a\";\n\n"
265+
},
266+
{
267+
"start":{
268+
"line":1,
269+
"offset":1
270+
},
271+
"end":{
272+
"line":1,
273+
"offset":1
274+
},
275+
"newText":"console.log(abc);"
276+
}
277+
]
278+
}
279+
],
280+
"fixId":"providePostPasteEdits"
281+
}
282+
}
283+
AfterRequest
284+
Projects::
285+
/tsconfig.json(Configured)*changed*
286+
projectStateVersion:3*changed*
287+
projectProgramVersion:1
288+
dirty:true*changed*
289+
290+
ScriptInfos::
291+
/a.ts
292+
version:Text-1
293+
containingProjects:1
294+
/tsconfig.json
295+
/b.ts
296+
version:Text-1
297+
containingProjects:1
298+
/tsconfig.json
299+
/c.ts(Open)*changed*
300+
version:SVC-1-2*changed*
301+
containingProjects:1
302+
/tsconfig.json*default*
303+
/lib.d.ts
304+
version:Text-1
305+
containingProjects:1
306+
/tsconfig.json
307+
/lib.decorators.d.ts
308+
version:Text-1
309+
containingProjects:1
310+
/tsconfig.json
311+
/lib.decorators.legacy.d.ts
312+
version:Text-1
313+
containingProjects:1
314+
/tsconfig.json

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp