-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document quick fix (or whatever it's officially called) #29048
Comments
What exactly were you trying to find when you started searching for quick fixes? |
Also
it sounds like this is a bug with how Atom's TypeScript integration is displaying suggestion diagnostics. If you're using ide-typescript you may want to file an issue there. CCing @damieng. |
I was seeing a list of suggestions in atom, that were coming from the typescript compiler - but that weren't showing up in the CLI, even though I thought I had the same settings enabled. When I googled the error message, i only got results for the messages JSON. The items in atom were showing up with a different colour line, so it was clear that they were suggestions rather than errors - but I didn't understand what configuration was producing them. I was poking around the CLI docs and For comparison, here's atom and vscode. If anything the vscode display is a bit off, as the squiggly line doesn't extend to the full expression. |
Oh, and the wording of |
"can be converted" is probably better.
That's the intent - it's supposed to appear as a subtle hint that you can take action on some code. We're not trying to surface these as something like linter warnings. |
Is there any way to get the list of quick fixes via the CLI yet? While these do show up when opening a file in VSCode, I am yet to find a way to list all possible fixes across a project |
The quick fixes are generated by the language service API, which currently isn't even a part of the cli build. So while you can write a program yourself against the TypeScript API that finds (and applies) all quickfixes, |
For anyone who interested import ts from 'typescript'
import { join } from 'path'
import { existsSync, readFileSync } from 'fs'
const compilerOptions: ts.CompilerOptions = {}
const host = ts.createCompilerHost(compilerOptions)
const program = ts.createProgram({
host: host,
rootNames: [join(__dirname, '../../my-project/src/index.ts')],
options: compilerOptions
})
const allFiles = program.getSourceFiles().map(x => x.fileName)
const languageService = ts.createLanguageService(
{
getCompilationSettings: () => compilerOptions,
getScriptFileNames: () => allFiles,
getScriptVersion: () => '0',
getCurrentDirectory() {
return join(__dirname, '../../my-project/src')
},
getDefaultLibFileName: options => ts.getDefaultLibFilePath(options),
fileExists: ts.sys.fileExists,
readFile: ts.sys.readFile,
readDirectory: ts.sys.readDirectory,
getScriptSnapshot: fileName => {
if (!existsSync(fileName)) {
return undefined
}
return ts.ScriptSnapshot.fromString(readFileSync(fileName).toString())
}
},
ts.createDocumentRegistry(true, '../../my-project/src')
)
for (const file of allFiles) {
const diags = languageService.getSuggestionDiagnostics(file)
for (const diag of diags) {
console.log(
`TS${diag.code}: ${ts.flattenDiagnosticMessageText(diag.messageText, ', ', 2)} | ${diag.file.fileName}`
)
}
} |
After reporting typescript-eslint/typescript-eslint#1786 I was lead here. As I do not use vscode, I was completely unaware that |
TypeScript Version: 3.3.0-dev.201xxxxx
Search Terms:
code fix
quick fix
suggestion
Code
not entirely applicable, but this is what I had which caused me to get confused
Expected behavior:
Commandline
tsc
should behave the same as editor integrationsActual behavior:
The "quick fix" feature, which appears to be called "code fixes" in the codebase and googling the messages led me to the json file which refers to them as "suggestions", only appears to exist in the typescript server.
As a newcomer this had me extremely confused. I was running
tsc
on the commandline and getting no errors, but seeing squiggly lines and messages in my editor (atom, in this case).I was unable to find any documentation about where the message
'require' call may be converted to an import
was coming from, or that this was a hint that typescript was able to fix my code for me.It would also be helpful if the
tsc
client was able to list the code fix suggestions, even if giving it a way to apply them would be too complex.Playground Link:
n/a
Related Issues:
none that I could find
The text was updated successfully, but these errors were encountered: