@tsslint/typescript-plugin 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -46,8 +46,7 @@ const init = (modules) => {
46
46
  function decorateLanguageService(ts, tsconfig, info) {
47
47
  const getCompilerOptionsDiagnostics = info.languageService.getCompilerOptionsDiagnostics;
48
48
  const getSyntacticDiagnostics = info.languageService.getSyntacticDiagnostics;
49
- const getApplicableRefactors = info.languageService.getApplicableRefactors;
50
- const getEditsForRefactor = info.languageService.getEditsForRefactor;
49
+ const getCodeFixesAtPosition = info.languageService.getCodeFixesAtPosition;
51
50
  let configFile;
52
51
  let configFileBuildContext;
53
52
  let configFileDiagnostics = [];
@@ -60,7 +59,7 @@ function decorateLanguageService(ts, tsconfig, info) {
60
59
  let errors = getSyntacticDiagnostics(fileName);
61
60
  errors = errors.concat(configFileDiagnostics);
62
61
  const sourceFile = info.languageService.getProgram()?.getSourceFile(fileName);
63
- if (!sourceFile) {
62
+ if (!sourceFile || sourceFile.text.length > 20000) {
64
63
  return errors;
65
64
  }
66
65
  const token = info.languageServiceHost.getCancellationToken?.();
@@ -80,7 +79,7 @@ function decorateLanguageService(ts, tsconfig, info) {
80
79
  }
81
80
  if (config?.debug) {
82
81
  errors.push({
83
- category: ts.DiagnosticCategory.Message,
82
+ category: ts.DiagnosticCategory.Warning,
84
83
  source: 'tsslint',
85
84
  code: 'debug-info',
86
85
  messageText: JSON.stringify({
@@ -96,33 +95,16 @@ function decorateLanguageService(ts, tsconfig, info) {
96
95
  }
97
96
  return errors;
98
97
  };
99
- info.languageService.getApplicableRefactors = (fileName, positionOrRange, ...rest) => {
100
- let refactors = getApplicableRefactors(fileName, positionOrRange, ...rest);
101
- const sourceFile = info.languageService.getProgram()?.getSourceFile(fileName);
102
- if (!sourceFile) {
103
- return refactors;
104
- }
98
+ info.languageService.getCodeFixesAtPosition = (fileName, start, end, errorCodes, formatOptions, preferences) => {
99
+ let fixes = getCodeFixesAtPosition(fileName, start, end, errorCodes, formatOptions, preferences);
105
100
  const token = info.languageServiceHost.getCancellationToken?.();
106
101
  for (const plugin of plugins) {
107
102
  if (token?.isCancellationRequested()) {
108
103
  break;
109
104
  }
110
- refactors = refactors.concat(plugin.getFixes?.(sourceFile, positionOrRange) ?? []);
111
- }
112
- return refactors;
113
- };
114
- info.languageService.getEditsForRefactor = (fileName, formatOptions, positionOrRange, refactorName, actionName, ...rest) => {
115
- const sourceFile = info.languageService.getProgram()?.getSourceFile(fileName);
116
- if (!sourceFile) {
117
- return;
118
- }
119
- for (const plugin of plugins) {
120
- const edits = plugin.fix?.(sourceFile, refactorName, actionName);
121
- if (edits) {
122
- return { edits };
123
- }
105
+ fixes = fixes.concat(plugin.getFixes?.(fileName, start, end, errorCodes) ?? []);
124
106
  }
125
- return getEditsForRefactor(fileName, formatOptions, positionOrRange, refactorName, actionName, ...rest);
107
+ return fixes;
126
108
  };
127
109
  return { update };
128
110
  async function update(pluginConfig) {
@@ -131,40 +131,25 @@ exports.builtInPlugins = [
131
131
  };
132
132
  }
133
133
  },
134
- getFixes(sourceFile, positionOrRange) {
135
- const start = typeof positionOrRange === 'number' ? positionOrRange : positionOrRange.pos;
136
- const end = typeof positionOrRange === 'number' ? positionOrRange : positionOrRange.end;
137
- const fixes = getFileFixes(sourceFile.fileName);
138
- const refactors = [];
139
- for (const [errorCode, _fixes] of fixes) {
140
- for (let i = 0; i < _fixes.length; i++) {
141
- const fix = _fixes[i];
142
- if ((start <= fix.start && end >= fix.end) ||
134
+ getFixes(fileName, start, end) {
135
+ const fixesMap = getFileFixes(fileName);
136
+ const result = [];
137
+ for (const [_errorCode, fixes] of fixesMap) {
138
+ for (let i = 0; i < fixes.length; i++) {
139
+ const fix = fixes[i];
140
+ if ((fix.start >= start && fix.start <= end) ||
141
+ (fix.end >= start && fix.end <= end) ||
143
142
  (start >= fix.start && start <= fix.end) ||
144
143
  (end >= fix.start && end <= fix.end)) {
145
- if (refactors[refactors.length - 1]?.name !== 'tsslint/fix') {
146
- refactors.push({
147
- name: 'tsslint/fix',
148
- description: 'Fix ' + errorCode,
149
- actions: [],
150
- });
151
- }
152
- refactors[refactors.length - 1].actions.push({
153
- name: errorCode + '-' + i,
144
+ result.push({
145
+ fixName: `tsslint: ${fix.title}`,
154
146
  description: fix.title,
147
+ changes: fix.getEdits(),
155
148
  });
156
149
  }
157
150
  }
158
151
  }
159
- return refactors;
160
- },
161
- fix(sourceFile, refactorName, actionName) {
162
- if (refactorName === 'tsslint/fix') {
163
- const errorCode = actionName.substring(0, actionName.lastIndexOf('-'));
164
- const fixIndex = actionName.substring(actionName.lastIndexOf('-') + 1);
165
- const fix = getFileFixes(sourceFile.fileName).get(errorCode)[Number(fixIndex)];
166
- return fix.getEdits();
167
- }
152
+ return result;
168
153
  },
169
154
  };
170
155
  function getFileFixes(fileName) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsslint/typescript-plugin",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -16,7 +16,7 @@
16
16
  "source-map-support": "^0.5.19"
17
17
  },
18
18
  "devDependencies": {
19
- "@tsslint/config": "0.0.2"
19
+ "@tsslint/config": "0.0.3"
20
20
  },
21
- "gitHead": "bdca2792d8b64a11c7c1632c80a2bf25b4985c15"
21
+ "gitHead": "13557d614907865f38ad32fd3582c9f198fb9ffa"
22
22
  }