MCPcopy Create free account
hub / github.com/adobe/react-spectrum / create

Function create

packages/dev/ts-plugin/src/index.js:15–52  ·  view source on GitHub ↗

@param info {import('typescript').server.PluginCreateInfo}

(info)

Source from the content-addressed store, hash-verified

13module.exports = function () {
14 /** @param info {import('typescript').server.PluginCreateInfo} */
15 function create(info) {
16 const proxy = Object.create(null);
17 for (let k of Object.keys(info.languageService)) {
18 const x = info.languageService[k];
19 proxy[k] = (...args) => x.apply(info.languageService, args);
20 }
21
22 proxy.getCompletionEntryDetails = (...args) => {
23 let result = info.languageService.getCompletionEntryDetails(...args);
24 if (!result.codeActions) {
25 return result;
26 }
27
28 // Override auto import of style macro to add `with {type: 'macro'}` automatically.
29 for (let action of result.codeActions) {
30 for (let change of action.changes) {
31 for (let textChange of change.textChanges) {
32 if (change.fileName.includes('@react-spectrum/s2')) {
33 // For files inside S2 itself, import specifier will be '../style', not '@react-spectrum/s2/style'.
34 textChange.newText = textChange.newText.replace(
35 /(import\s*\{.*?\}\s*from\s*['"]\.\.\/style['"]);/g,
36 "$1 with {type: 'macro'};"
37 );
38 } else {
39 textChange.newText = textChange.newText.replace(
40 /(import\s*\{.*?\}\s*from\s*['"]@react-spectrum\/s2\/style['"]);/g,
41 "$1 with {type: 'macro'};"
42 );
43 }
44 }
45 }
46 }
47
48 return result;
49 };
50
51 return proxy;
52 }
53
54 return {create};
55};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected