-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow diagnostic code lookup on the web
In some cases, like for misra rule checking with CppCheck, no useful description is available from the tool. This change introduces the ability to search the diagnostic code on the web for more information. The query base Uri and the set of words to match to activate the behavior are configurable through settings. For security reasons, the query base Uri is only configurable from trusted workspaces. The feature also only activates when the language server doesn't already provide a link in the generated diagnostic.
- Loading branch information
Showing
3 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {LanguageClient, LanguageClientOptions, ServerOptions} from 'vscode-languageclient/node'; | ||
import * as ls from 'vscode-languageserver'; | ||
import * as code from 'vscode'; | ||
|
||
export class FlylintLanguageClient extends LanguageClient { | ||
constructor( | ||
id: string, | ||
name: string, | ||
serverOptions: ServerOptions, | ||
clientOptions: LanguageClientOptions, | ||
queryUrlStr: string, | ||
matchSet: string[], | ||
forceDebug?: boolean | ||
) { | ||
super(id, name, serverOptions, clientOptions, forceDebug); | ||
let originalAsDiagnostic = this.protocol2CodeConverter.asDiagnostic; | ||
this.protocol2CodeConverter.asDiagnostic = ((diagnostic: ls.Diagnostic): code.Diagnostic => { | ||
let result = originalAsDiagnostic(diagnostic); | ||
if ((result.code !== undefined) && (typeof result.code === 'string') && (queryUrlStr.length > 0)) { | ||
let codeStr = String(result.code); | ||
if (matchSet.some(v => codeStr.includes(v))) { | ||
result.code = { | ||
value: result.code, | ||
target: this.protocol2CodeConverter.asUri(`${queryUrlStr}${result.source}%20${result.code}`) | ||
}; | ||
} | ||
} | ||
return result; | ||
}); | ||
this.protocol2CodeConverter.asDiagnostics = ((diagnostics: ls.Diagnostic[]): code.Diagnostic[] => { | ||
return diagnostics.map(this.protocol2CodeConverter.asDiagnostic); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters