Remove language service dependency on TextDocuments (#742)

The code actions API depends on `TextDocuments`. This is specific to the
language server. This makes it hard to use without a language server.

The use of `TextDocuments` has been removed. Instead, the resolved text
document is passed down.
master
Remco Haszing 2023-03-27 19:39:56 +02:00 committed by GitHub
parent 33f94bae1a
commit ae18cb2449
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 9 deletions

View File

@ -412,7 +412,6 @@ async function createProjectService(
diagnosticRelatedInformation: true,
itemDefaults,
},
documents: documentService.documents,
getConfiguration,
getDocumentSymbols: (uri: string) => {
return connection.sendRequest('@/tailwindCSS/getDocumentSymbols', { uri })
@ -1171,7 +1170,7 @@ async function createProjectService(
if (!document) return null
let settings = await state.editor.getConfiguration(document.uri)
if (!settings.tailwindCSS.codeActions) return null
return doCodeActions(state, params)
return doCodeActions(state, params, document)
}, null)
},
onDocumentLinks(params: DocumentLinkParams): DocumentLink[] {

View File

@ -17,13 +17,14 @@ import { flatten, dedupeBy } from '../util/array'
import { provideCssConflictCodeActions } from './provideCssConflictCodeActions'
import { provideInvalidApplyCodeActions } from './provideInvalidApplyCodeActions'
import { provideSuggestionCodeActions } from './provideSuggestionCodeActions'
import { TextDocument } from 'vscode-languageserver-textdocument'
async function getDiagnosticsFromCodeActionParams(
state: State,
params: CodeActionParams,
document: TextDocument,
only?: DiagnosticKind[]
): Promise<AugmentedDiagnostic[]> {
let document = state.editor.documents.get(params.textDocument.uri)
if (!document) return []
let diagnostics = await doValidate(state, document, only)
@ -40,7 +41,7 @@ async function getDiagnosticsFromCodeActionParams(
.filter(Boolean)
}
export async function doCodeActions(state: State, params: CodeActionParams): Promise<CodeAction[]> {
export async function doCodeActions(state: State, params: CodeActionParams, document: TextDocument): Promise<CodeAction[]> {
if (!state.enabled) {
return []
}
@ -48,6 +49,7 @@ export async function doCodeActions(state: State, params: CodeActionParams): Pro
let diagnostics = await getDiagnosticsFromCodeActionParams(
state,
params,
document,
params.context.diagnostics
.map((diagnostic) => diagnostic.code)
.filter(Boolean) as DiagnosticKind[]
@ -56,7 +58,7 @@ export async function doCodeActions(state: State, params: CodeActionParams): Pro
return Promise.all(
diagnostics.map((diagnostic) => {
if (isInvalidApplyDiagnostic(diagnostic)) {
return provideInvalidApplyCodeActions(state, params, diagnostic)
return provideInvalidApplyCodeActions(state, document, diagnostic)
}
if (isCssConflictDiagnostic(diagnostic)) {

View File

@ -18,13 +18,13 @@ import { dset } from 'dset'
import selectorParser from 'postcss-selector-parser'
import { flatten } from '../util/array'
import { getTextWithoutComments } from '../util/doc'
import { TextDocument } from 'vscode-languageserver-textdocument'
export async function provideInvalidApplyCodeActions(
state: State,
params: CodeActionParams,
document: TextDocument,
diagnostic: InvalidApplyDiagnostic
): Promise<CodeAction[]> {
let document = state.editor.documents.get(params.textDocument.uri)
if (!document) return []
let documentText = getTextWithoutComments(document, 'css')
let cssRange: Range
@ -144,7 +144,7 @@ export async function provideInvalidApplyCodeActions(
diagnostics: [diagnostic],
edit: {
changes: {
[params.textDocument.uri]: changes,
[document.uri]: changes,
},
},
},

View File

@ -20,7 +20,6 @@ export type ClassNames = {
export type EditorState = {
connection: Connection
folder: string
documents: TextDocuments<TextDocument>
userLanguages: Record<string, string>
capabilities: {
configuration: boolean