-
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.
Co-authored-by: Erika <[email protected]> Co-authored-by: Johnson Chu <[email protected]>
- Loading branch information
1 parent
a2eee58
commit 6a13528
Showing
5 changed files
with
280 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "volar-service-yaml", | ||
"version": "0.0.11", | ||
"main": "out/index.js", | ||
"license": "MIT", | ||
"files": [ | ||
"out/**/*.js", | ||
"out/**/*.d.ts" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/volarjs/services.git", | ||
"directory": "packages/yaml" | ||
}, | ||
"dependencies": { | ||
"yaml-language-server": "1.14.0" | ||
}, | ||
"devDependencies": { | ||
"vscode-languageserver-textdocument": "^1.0.8" | ||
}, | ||
"peerDependencies": { | ||
"@volar/language-service": "~1.10.0" | ||
}, | ||
"peerDependenciesMeta": { | ||
"@volar/language-service": { | ||
"optional": true | ||
} | ||
} | ||
} |
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,129 @@ | ||
import { type Service } from '@volar/language-service'; | ||
import { type TextDocument } from 'vscode-languageserver-textdocument'; | ||
import { type LanguageSettings, type LanguageService } from 'yaml-language-server'; | ||
import { getLanguageService } from 'yaml-language-server'; | ||
|
||
export interface Provide { | ||
'yaml/languageService': () => LanguageService; | ||
} | ||
|
||
function isYaml(document: TextDocument): boolean { | ||
return document.languageId === 'yaml'; | ||
} | ||
|
||
function noop(): undefined { } | ||
|
||
/** | ||
* Create a Volar language service for YAML documents. | ||
*/ | ||
export default (settings: LanguageSettings): Service<Provide> => { | ||
return (context): ReturnType<Service<Provide>> => { | ||
|
||
if (!context) { | ||
return { triggerCharacters: [' ', ':'] } as any; | ||
} | ||
|
||
const ls = getLanguageService({ | ||
schemaRequestService: async (uri) => await context.env.fs?.readFile(uri) ?? '', | ||
telemetry: { | ||
send: noop, | ||
sendError: noop, | ||
sendTrack: noop | ||
}, | ||
// @ts-expect-error https://github.com/redhat-developer/yaml-language-server/pull/910 | ||
clientCapabilities: context?.env?.clientCapabilities, | ||
workspaceContext: { | ||
resolveRelativePath(relativePath, resource) { | ||
return String(new URL(relativePath, resource)); | ||
} | ||
}, | ||
}); | ||
|
||
ls.configure({ | ||
completion: true, | ||
customTags: [], | ||
format: true, | ||
hover: true, | ||
isKubernetes: false, | ||
validate: true, | ||
yamlVersion: '1.2', | ||
...settings | ||
}); | ||
|
||
return { | ||
provide: { | ||
'yaml/languageService': () => ls | ||
}, | ||
|
||
triggerCharacters: [' ', ':'], | ||
|
||
provideCodeActions(document, range, context) { | ||
if (isYaml(document)) { | ||
return ls.getCodeAction(document, { | ||
context, | ||
range, | ||
textDocument: document | ||
}); | ||
} | ||
}, | ||
|
||
provideCodeLenses(document) { | ||
if (isYaml(document)) { | ||
return ls.getCodeLens(document); | ||
} | ||
}, | ||
|
||
provideCompletionItems(document, position) { | ||
if (isYaml(document)) { | ||
return ls.doComplete(document, position, false); | ||
} | ||
}, | ||
|
||
provideDefinition(document, position) { | ||
if (isYaml(document)) { | ||
return ls.doDefinition(document, { position, textDocument: document }); | ||
} | ||
}, | ||
|
||
provideDiagnostics(document) { | ||
if (isYaml(document)) { | ||
return ls.doValidation(document, false); | ||
} | ||
}, | ||
|
||
provideDocumentSymbols(document) { | ||
if (isYaml(document)) { | ||
return ls.findDocumentSymbols2(document, {}); | ||
} | ||
}, | ||
|
||
provideHover(document, position) { | ||
if (isYaml(document)) { | ||
return ls.doHover(document, position); | ||
} | ||
}, | ||
|
||
provideDocumentLinks(document) { | ||
if (isYaml(document)) { | ||
return ls.findLinks(document); | ||
} | ||
}, | ||
|
||
provideFoldingRanges(document) { | ||
if (isYaml(document)) { | ||
return ls.getFoldingRanges(document, {}); | ||
} | ||
}, | ||
|
||
provideSelectionRanges(document, positions) { | ||
if (isYaml(document)) { | ||
return ls.getSelectionRanges(document, positions); | ||
} | ||
}, | ||
|
||
resolveCodeLens(codeLens) { | ||
return ls.resolveCodeLens(codeLens); | ||
}, | ||
}; | ||
}; | ||
} |
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,11 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"noEmit": false, | ||
"outDir": "out", | ||
"rootDir": "src", | ||
}, | ||
"include": [ | ||
"src", | ||
], | ||
} |
Oops, something went wrong.