Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 59e6620

Browse files
authored
Fixing self import (#58718)
1 parent bbfc1aa commit 59e6620

File tree

3 files changed

+311
-1
lines changed

3 files changed

+311
-1
lines changed

src/services/refactors/moveToFile.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ export function getExistingLocals(sourceFile: SourceFile, statements: readonly S
11491149
for (const statement of statements) {
11501150
forEachReference(statement, checker, s => {
11511151
const symbol = skipAlias(s, checker);
1152-
if (symbol.valueDeclaration && getSourceFileOfNode(symbol.valueDeclaration) === sourceFile) {
1152+
if (symbol.valueDeclaration && getSourceFileOfNode(symbol.valueDeclaration).path === sourceFile.path) {
11531153
existingLocals.add(symbol);
11541154
}
11551155
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
currentDirectory:: / useCaseSensitiveFileNames: false
2+
Info seq [hh:mm:ss:mss] Provided types map file "/typesMap.json" doesn't exist
3+
//// [/lib.d.ts]
4+
lib.d.ts-Text
5+
6+
//// [/lib.decorators.d.ts]
7+
lib.decorators.d.ts-Text
8+
9+
//// [/lib.decorators.legacy.d.ts]
10+
lib.decorators.legacy.d.ts-Text
11+
12+
//// [/target.ts]
13+
const k = 1;
14+
console.log(k);
15+
16+
17+
console.log("test");
18+
19+
//// [/tsconfig.json]
20+
{ "files": ["target.ts"] }
21+
22+
23+
Info seq [hh:mm:ss:mss] request:
24+
{
25+
"seq": 0,
26+
"type": "request",
27+
"arguments": {
28+
"file": "/target.ts"
29+
},
30+
"command": "open"
31+
}
32+
Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /target.ts ProjectRootPath: undefined:: Result: /tsconfig.json
33+
Info seq [hh:mm:ss:mss] Creating configuration project /tsconfig.json
34+
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tsconfig.json 2000 undefined Project: /tsconfig.json WatchType: Config file
35+
Info seq [hh:mm:ss:mss] event:
36+
{
37+
"seq": 0,
38+
"type": "event",
39+
"event": "projectLoadingStart",
40+
"body": {
41+
"projectName": "/tsconfig.json",
42+
"reason": "Creating possible configured project for /target.ts to open"
43+
}
44+
}
45+
Info seq [hh:mm:ss:mss] Config: /tsconfig.json : {
46+
"rootNames": [
47+
"/target.ts"
48+
],
49+
"options": {
50+
"configFilePath": "/tsconfig.json"
51+
}
52+
}
53+
Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /tsconfig.json
54+
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /lib.d.ts 500 undefined WatchType: Closed Script info
55+
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /lib.decorators.d.ts 500 undefined WatchType: Closed Script info
56+
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /lib.decorators.legacy.d.ts 500 undefined WatchType: Closed Script info
57+
Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /tsconfig.json projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed:: *ms
58+
Info seq [hh:mm:ss:mss] Project '/tsconfig.json' (Configured)
59+
Info seq [hh:mm:ss:mss] Files (4)
60+
/lib.d.ts Text-1 lib.d.ts-Text
61+
/lib.decorators.d.ts Text-1 lib.decorators.d.ts-Text
62+
/lib.decorators.legacy.d.ts Text-1 lib.decorators.legacy.d.ts-Text
63+
/target.ts SVC-1-0 "const k = 1;\nconsole.log(k);\n\n\nconsole.log(\"test\");"
64+
65+
66+
lib.d.ts
67+
Default library for target 'es5'
68+
lib.decorators.d.ts
69+
Library referenced via 'decorators' from file 'lib.d.ts'
70+
lib.decorators.legacy.d.ts
71+
Library referenced via 'decorators.legacy' from file 'lib.d.ts'
72+
target.ts
73+
Part of 'files' list in tsconfig.json
74+
75+
Info seq [hh:mm:ss:mss] -----------------------------------------------
76+
Info seq [hh:mm:ss:mss] event:
77+
{
78+
"seq": 0,
79+
"type": "event",
80+
"event": "projectLoadingFinish",
81+
"body": {
82+
"projectName": "/tsconfig.json"
83+
}
84+
}
85+
Info seq [hh:mm:ss:mss] event:
86+
{
87+
"seq": 0,
88+
"type": "event",
89+
"event": "configFileDiag",
90+
"body": {
91+
"triggerFile": "/target.ts",
92+
"configFile": "/tsconfig.json",
93+
"diagnostics": []
94+
}
95+
}
96+
Info seq [hh:mm:ss:mss] Project '/tsconfig.json' (Configured)
97+
Info seq [hh:mm:ss:mss] Files (4)
98+
99+
Info seq [hh:mm:ss:mss] -----------------------------------------------
100+
Info seq [hh:mm:ss:mss] Open files:
101+
Info seq [hh:mm:ss:mss] FileName: /target.ts ProjectRootPath: undefined
102+
Info seq [hh:mm:ss:mss] Projects: /tsconfig.json
103+
After Request
104+
watchedFiles::
105+
/lib.d.ts: *new*
106+
{"pollingInterval":500}
107+
/lib.decorators.d.ts: *new*
108+
{"pollingInterval":500}
109+
/lib.decorators.legacy.d.ts: *new*
110+
{"pollingInterval":500}
111+
/tsconfig.json: *new*
112+
{"pollingInterval":2000}
113+
114+
Projects::
115+
/tsconfig.json (Configured) *new*
116+
projectStateVersion: 1
117+
projectProgramVersion: 1
118+
119+
ScriptInfos::
120+
/lib.d.ts *new*
121+
version: Text-1
122+
containingProjects: 1
123+
/tsconfig.json
124+
/lib.decorators.d.ts *new*
125+
version: Text-1
126+
containingProjects: 1
127+
/tsconfig.json
128+
/lib.decorators.legacy.d.ts *new*
129+
version: Text-1
130+
containingProjects: 1
131+
/tsconfig.json
132+
/target.ts (Open) *new*
133+
version: SVC-1-0
134+
containingProjects: 1
135+
/tsconfig.json *default*
136+
137+
Info seq [hh:mm:ss:mss] request:
138+
{
139+
"seq": 1,
140+
"type": "request",
141+
"arguments": {
142+
"formatOptions": {
143+
"indentSize": 4,
144+
"tabSize": 4,
145+
"newLineCharacter": "\n",
146+
"convertTabsToSpaces": true,
147+
"indentStyle": 2,
148+
"insertSpaceAfterConstructor": false,
149+
"insertSpaceAfterCommaDelimiter": true,
150+
"insertSpaceAfterSemicolonInForStatements": true,
151+
"insertSpaceBeforeAndAfterBinaryOperators": true,
152+
"insertSpaceAfterKeywordsInControlFlowStatements": true,
153+
"insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
154+
"insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
155+
"insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
156+
"insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true,
157+
"insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false,
158+
"insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false,
159+
"insertSpaceBeforeFunctionParenthesis": false,
160+
"placeOpenBraceOnNewLineForFunctions": false,
161+
"placeOpenBraceOnNewLineForControlBlocks": false,
162+
"semicolons": "ignore",
163+
"trimTrailingWhitespace": true,
164+
"indentSwitchCase": true
165+
}
166+
},
167+
"command": "configure"
168+
}
169+
Info seq [hh:mm:ss:mss] Format host information updated
170+
Info seq [hh:mm:ss:mss] response:
171+
{
172+
"seq": 0,
173+
"type": "response",
174+
"command": "configure",
175+
"request_seq": 1,
176+
"success": true
177+
}
178+
Info seq [hh:mm:ss:mss] request:
179+
{
180+
"seq": 2,
181+
"type": "request",
182+
"arguments": {
183+
"file": "/target.ts",
184+
"pastedText": [
185+
"console.log(k);"
186+
],
187+
"pasteLocations": [
188+
{
189+
"start": {
190+
"line": 4,
191+
"offset": 1
192+
},
193+
"end": {
194+
"line": 4,
195+
"offset": 1
196+
}
197+
}
198+
],
199+
"copiedFrom": {
200+
"file": "target.ts",
201+
"spans": [
202+
{
203+
"start": {
204+
"line": 2,
205+
"offset": 1
206+
},
207+
"end": {
208+
"line": 2,
209+
"offset": 16
210+
}
211+
}
212+
]
213+
}
214+
},
215+
"command": "getPasteEdits"
216+
}
217+
Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /tsconfig.json
218+
Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /tsconfig.json projectStateVersion: 2 projectProgramVersion: 1 structureChanged: false structureIsReused:: Completely Elapsed:: *ms
219+
Info seq [hh:mm:ss:mss] Project '/tsconfig.json' (Configured)
220+
Info seq [hh:mm:ss:mss] Files (4)
221+
/lib.d.ts Text-1 lib.d.ts-Text
222+
/lib.decorators.d.ts Text-1 lib.decorators.d.ts-Text
223+
/lib.decorators.legacy.d.ts Text-1 lib.decorators.legacy.d.ts-Text
224+
/target.ts SVC-1-1 "const k = 1;\nconsole.log(k);\n\nconsole.log(k);\nconsole.log(\"test\");"
225+
226+
Info seq [hh:mm:ss:mss] -----------------------------------------------
227+
Info seq [hh:mm:ss:mss] response:
228+
{
229+
"seq": 0,
230+
"type": "response",
231+
"command": "getPasteEdits",
232+
"request_seq": 2,
233+
"success": true,
234+
"performanceData": {
235+
"updateGraphDurationMs": *
236+
},
237+
"body": {
238+
"edits": [
239+
{
240+
"fileName": "/target.ts",
241+
"textChanges": [
242+
{
243+
"start": {
244+
"line": 4,
245+
"offset": 1
246+
},
247+
"end": {
248+
"line": 4,
249+
"offset": 1
250+
},
251+
"newText": "console.log(k);"
252+
}
253+
]
254+
}
255+
],
256+
"fixId": "providePostPasteEdits"
257+
}
258+
}
259+
After Request
260+
Projects::
261+
/tsconfig.json (Configured) *changed*
262+
projectStateVersion: 3 *changed*
263+
projectProgramVersion: 1
264+
dirty: true *changed*
265+
266+
ScriptInfos::
267+
/lib.d.ts
268+
version: Text-1
269+
containingProjects: 1
270+
/tsconfig.json
271+
/lib.decorators.d.ts
272+
version: Text-1
273+
containingProjects: 1
274+
/tsconfig.json
275+
/lib.decorators.legacy.d.ts
276+
version: Text-1
277+
containingProjects: 1
278+
/tsconfig.json
279+
/target.ts (Open) *changed*
280+
version: SVC-1-2 *changed*
281+
containingProjects: 1
282+
/tsconfig.json *default*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/// <reference path="../fourslash.ts" />
2+
3+
// @Filename: /target.ts
4+
//// const k = 1;
5+
//// [|console.log(k);|]
6+
////
7+
//// [||]
8+
//// console.log("test");
9+
10+
// @Filename: /tsconfig.json
11+
////{ "files": ["target.ts"] }
12+
13+
const range = test.ranges();
14+
verify.pasteEdits({
15+
args: {
16+
pastedText: [ `console.log(k);`],
17+
pasteLocations: [range[1]],
18+
copiedFrom: { file: "target.ts", range: [range[0]] },
19+
},
20+
newFileContents: {
21+
"/target.ts":
22+
`const k = 1;
23+
console.log(k);
24+
25+
console.log(k);
26+
console.log("test");`
27+
}
28+
});

0 commit comments

Comments
 (0)